forked from CGM_Public/pretix_original
Added python3.5-style type annotations to pretix.base
This commit is contained in:
@@ -12,13 +12,13 @@ class UserManager(BaseUserManager):
|
||||
model documentation to see what's so special about our user model.
|
||||
"""
|
||||
|
||||
def create_user(self, email, password=None, **kwargs):
|
||||
def create_user(self, email: str, password: str=None, **kwargs):
|
||||
user = self.model(email=email, **kwargs)
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
return user
|
||||
|
||||
def create_superuser(self, email, password=None): # NOQA
|
||||
def create_superuser(self, email: str, password: str=None): # NOQA
|
||||
# Not used in the software but required by Django
|
||||
if password is None:
|
||||
raise Exception("You must provide a password")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import copy
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
import six
|
||||
from django.db import models
|
||||
@@ -12,7 +13,7 @@ class Versionable(BaseVersionable):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def clone_shallow(self, forced_version_date=None):
|
||||
def clone_shallow(self, forced_version_date: datetime=None):
|
||||
"""
|
||||
This behaves like clone(), but misses all the Many2Many-relation-handling. This is
|
||||
a performance optimization for cases in which we have to handle the Many2Many relations
|
||||
@@ -63,7 +64,7 @@ class Versionable(BaseVersionable):
|
||||
})
|
||||
|
||||
|
||||
def cachedfile_name(instance, filename):
|
||||
def cachedfile_name(instance, filename: str) -> str:
|
||||
return 'cachedfiles/%s.%s' % (instance.id, filename.split('.')[-1])
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from itertools import product
|
||||
|
||||
from django.db import models
|
||||
@@ -6,6 +8,7 @@ from django.db.models import Q, Case, Count, Sum, When
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from typing import List, Tuple, Union
|
||||
from versions.models import VersionedForeignKey, VersionedManyToManyField
|
||||
|
||||
from pretix.base.i18n import I18nCharField, I18nTextField
|
||||
@@ -61,11 +64,11 @@ class ItemCategory(Versionable):
|
||||
def sortkey(self):
|
||||
return self.position, self.version_birth_date
|
||||
|
||||
def __lt__(self, other):
|
||||
def __lt__(self, other) -> bool:
|
||||
return self.sortkey < other.sortkey
|
||||
|
||||
|
||||
def itempicture_upload_to(instance, filename):
|
||||
def itempicture_upload_to(instance, filename: str) -> str:
|
||||
return '%s/%s/item-%s.%s' % (
|
||||
instance.event.organizer.slug, instance.event.slug, instance.identity,
|
||||
filename.split('.')[-1]
|
||||
@@ -170,7 +173,7 @@ class Item(Versionable):
|
||||
if self.event:
|
||||
self.event.get_cache().clear()
|
||||
|
||||
def get_all_variations(self, use_cache: bool=False) -> "list[VariationDict]":
|
||||
def get_all_variations(self, use_cache: bool=False) -> List[VariationDict]:
|
||||
"""
|
||||
This method returns a list containing all variations of this
|
||||
item. The list contains one VariationDict per variation, where
|
||||
@@ -438,10 +441,10 @@ class PropertyValue(Versionable):
|
||||
self.prop.event.get_cache().clear()
|
||||
|
||||
@property
|
||||
def sortkey(self):
|
||||
def sortkey(self) -> Tuple[int, datetime]:
|
||||
return self.position, self.version_birth_date
|
||||
|
||||
def __lt__(self, other):
|
||||
def __lt__(self, other) -> bool:
|
||||
return self.sortkey < other.sortkey
|
||||
|
||||
|
||||
@@ -508,7 +511,7 @@ class ItemVariation(Versionable):
|
||||
if self.item:
|
||||
self.item.event.get_cache().clear()
|
||||
|
||||
def check_quotas(self):
|
||||
def check_quotas(self) -> Tuple[int, int]:
|
||||
"""
|
||||
This method is used to determine whether this ItemVariation is currently
|
||||
available for sale in terms of quotas.
|
||||
@@ -518,7 +521,7 @@ class ItemVariation(Versionable):
|
||||
return min([q.availability() for q in self.quotas.all()],
|
||||
key=lambda s: (s[0], s[1] if s[1] is not None else sys.maxsize))
|
||||
|
||||
def to_variation_dict(self):
|
||||
def to_variation_dict(self) -> VariationDict:
|
||||
"""
|
||||
:return: a :py:class:`VariationDict` representing this variation.
|
||||
"""
|
||||
@@ -528,7 +531,7 @@ class ItemVariation(Versionable):
|
||||
vd['variation'] = self
|
||||
return vd
|
||||
|
||||
def check_restrictions(self):
|
||||
def check_restrictions(self) -> Union[bool, Decimal]:
|
||||
"""
|
||||
This method is used to determine whether this ItemVariation is restricted
|
||||
in sale by any restriction plugins.
|
||||
@@ -806,7 +809,7 @@ class Quota(Versionable):
|
||||
if self.event:
|
||||
self.event.get_cache().clear()
|
||||
|
||||
def availability(self):
|
||||
def availability(self) -> Tuple[int, int]:
|
||||
"""
|
||||
This method is used to determine whether Items or ItemVariations belonging
|
||||
to this quota should currently be available for sale.
|
||||
@@ -864,7 +867,7 @@ class Quota(Versionable):
|
||||
return o
|
||||
|
||||
@cached_property
|
||||
def _position_lookup(self):
|
||||
def _position_lookup(self) -> Q:
|
||||
return (
|
||||
( # Orders for items which do not have any variations
|
||||
Q(variation__isnull=True)
|
||||
|
||||
@@ -5,6 +5,7 @@ from datetime import datetime
|
||||
from django.db import models
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from typing import List, Union
|
||||
from versions.models import VersionedForeignKey
|
||||
|
||||
from .base import CachedFile, Versionable
|
||||
@@ -133,7 +134,7 @@ class Order(Versionable):
|
||||
verbose_name_plural = _("Orders")
|
||||
ordering = ("-datetime",)
|
||||
|
||||
def str(self):
|
||||
def __str__(self):
|
||||
return self.full_code
|
||||
|
||||
@property
|
||||
@@ -160,7 +161,7 @@ class Order(Versionable):
|
||||
return
|
||||
|
||||
@property
|
||||
def can_modify_answers(self):
|
||||
def can_modify_answers(self) -> bool:
|
||||
"""
|
||||
Is ``True`` if the user can change the question answers / attendee names that are
|
||||
related to the order. This checks order status and modification deadlines. It also
|
||||
@@ -187,7 +188,7 @@ class Order(Versionable):
|
||||
order.save()
|
||||
return order
|
||||
|
||||
def _can_be_paid(self):
|
||||
def _can_be_paid(self) -> Union[bool, str]:
|
||||
error_messages = {
|
||||
'late': _("The payment is too late to be accepted."),
|
||||
}
|
||||
@@ -202,7 +203,7 @@ class Order(Versionable):
|
||||
|
||||
return self._is_still_available()
|
||||
|
||||
def _is_still_available(self):
|
||||
def _is_still_available(self) -> Union[bool, str]:
|
||||
error_messages = {
|
||||
'unavailable': _('Some of the ordered products were no longer available.'),
|
||||
}
|
||||
@@ -339,7 +340,7 @@ class OrderPosition(ObjectWithAnswers, Versionable):
|
||||
verbose_name_plural = _("Order positions")
|
||||
|
||||
@classmethod
|
||||
def transform_cart_positions(cls, cp: list, order) -> list:
|
||||
def transform_cart_positions(cls, cp: List, order) -> list:
|
||||
ops = []
|
||||
for cartpos in cp:
|
||||
op = OrderPosition(
|
||||
|
||||
@@ -45,7 +45,7 @@ class Organizer(Versionable):
|
||||
verbose_name_plural = _("Organizers")
|
||||
ordering = ("name",)
|
||||
|
||||
def __str__(self):
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
@@ -97,7 +97,7 @@ class OrganizerPermission(Versionable):
|
||||
verbose_name = _("Organizer permission")
|
||||
verbose_name_plural = _("Organizer permissions")
|
||||
|
||||
def __str__(self):
|
||||
def __str__(self) -> str:
|
||||
return _("%(name)s on %(object)s") % {
|
||||
'name': str(self.user),
|
||||
'object': str(self.organizer),
|
||||
|
||||
Reference in New Issue
Block a user