Upgrade to Django 3.2 (#2056)

This commit is contained in:
Raphael Michel
2021-05-07 12:00:30 +02:00
committed by GitHub
parent 0a7a3537eb
commit 403b8191e4
120 changed files with 1994 additions and 1555 deletions

View File

@@ -36,7 +36,13 @@ from pretix.helpers.json import CustomJSONEncoder
def cachedfile_name(instance, filename: str) -> str:
secret = get_random_string(length=12)
return 'cachedfiles/%s.%s.%s' % (instance.id, secret, filename.split('.')[-1])
return '%s.%s.%s' % (instance.id, secret, filename.split('.')[-1])
def _cachedfile_name(instance, filename: str) -> str:
# This was previously combined with cachedfile_name in one function, but a security patch for Django introduced
# additional file name validation in May 2021, and this was the best way to fix it without breaking plugins.
return 'cachedfiles/' + cachedfile_name(instance, filename)
class CachedFile(models.Model):
@@ -48,7 +54,7 @@ class CachedFile(models.Model):
date = models.DateTimeField(null=True, blank=True)
filename = models.CharField(max_length=255)
type = models.CharField(max_length=255)
file = models.FileField(null=True, blank=True, upload_to=cachedfile_name, max_length=255)
file = models.FileField(null=True, blank=True, upload_to=_cachedfile_name, max_length=255)
web_download = models.BooleanField(default=True) # allow web download, True for backwards compatibility in plugins
session_key = models.TextField(null=True, blank=True) # only allow download in this session

View File

@@ -39,7 +39,6 @@ from django.db.models import Exists, F, Max, OuterRef, Q, Subquery
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _, pgettext_lazy
from django_scopes import ScopedManager, scopes_disabled
from jsonfallback.fields import FallbackJSONField
from pretix.base.models import LoggedModel
from pretix.base.models.fields import MultiStringField
@@ -82,7 +81,7 @@ class CheckinList(LoggedModel):
'any of the selected sales channels. This option can be useful when tickets sold at the box office '
'are not checked again before entry and should be considered validated directly upon purchase.')
)
rules = FallbackJSONField(default=dict, blank=True)
rules = models.JSONField(default=dict, blank=True)
objects = ScopedManager(organizer='event__organizer')

View File

@@ -27,7 +27,6 @@ from django.db import models
from django.utils.crypto import get_random_string, salted_hmac
from django.utils.translation import gettext_lazy as _
from django_scopes import ScopedManager, scopes_disabled
from jsonfallback.fields import FallbackJSONField
from pretix.base.banlist import banned
from pretix.base.models.base import LoggedModel
@@ -45,7 +44,7 @@ class Customer(LoggedModel):
email = models.EmailField(db_index=True, null=True, blank=False, verbose_name=_('E-mail'), max_length=190)
password = models.CharField(verbose_name=_('Password'), max_length=128)
name_cached = models.CharField(max_length=255, verbose_name=_('Full name'), blank=True)
name_parts = FallbackJSONField(default=dict)
name_parts = models.JSONField(default=dict)
is_active = models.BooleanField(default=True, verbose_name=_('Account active'))
is_verified = models.BooleanField(default=True, verbose_name=_('Verified email address'))
last_login = models.DateTimeField(verbose_name=_('Last login'), blank=True, null=True)
@@ -60,6 +59,10 @@ class Customer(LoggedModel):
class Meta:
unique_together = [['organizer', 'email']]
ordering = ('email',)
def get_email_field_name(self):
return 'email'
def save(self, **kwargs):
if self.email:

View File

@@ -1270,7 +1270,8 @@ class SubEvent(EventMixin, LoggedModel):
).order_by().values('subevent').annotate(items=GroupConcat('item_id', delimiter=',')).values('items'),
output_field=models.TextField(),
),
Value('')
Value(''),
output_field=models.TextField()
),
disabled_vars=Coalesce(
Subquery(
@@ -1280,7 +1281,8 @@ class SubEvent(EventMixin, LoggedModel):
).order_by().values('subevent').annotate(items=GroupConcat('variation_id', delimiter=',')).values('items'),
output_field=models.TextField(),
),
Value('')
Value(''),
output_field=models.TextField()
)
)

View File

@@ -401,7 +401,7 @@ class Item(LoggedModel):
),
default=False
)
generate_tickets = models.NullBooleanField(
generate_tickets = models.BooleanField(
verbose_name=_("Generate tickets"),
blank=True, null=True,
)
@@ -410,7 +410,7 @@ class Item(LoggedModel):
help_text=_("This will only work if waiting lists are enabled for this event."),
default=True
)
show_quota_left = models.NullBooleanField(
show_quota_left = models.BooleanField(
verbose_name=_("Show number of tickets left"),
help_text=_("Publicly show how many tickets are still available."),
blank=True, null=True,

View File

@@ -27,7 +27,6 @@ from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _
from django_scopes import ScopedManager, scopes_disabled
from i18nfield.fields import I18nCharField
from jsonfallback.fields import FallbackJSONField
from pretix.base.models import Customer
from pretix.base.models.base import LoggedModel
@@ -59,6 +58,9 @@ class MembershipType(LoggedModel):
null=True, blank=True,
)
class Meta:
ordering = ('id',)
def __str__(self):
return str(self.name)
@@ -87,7 +89,7 @@ class MembershipQuerySet(models.QuerySet):
c=Count('*')
).values('c')
),
Value('0')
Value(0),
)
)
@@ -135,7 +137,7 @@ class Membership(models.Model):
date_end = models.DateTimeField(
verbose_name=_('End date')
)
attendee_name_parts = FallbackJSONField(default=dict, null=True)
attendee_name_parts = models.JSONField(default=dict, null=True)
objects = MembershipQuerySetManager()

View File

@@ -65,7 +65,6 @@ from django.utils.translation import gettext_lazy as _, pgettext_lazy
from django_countries.fields import Country
from django_scopes import ScopedManager, scopes_disabled
from i18nfield.strings import LazyI18nString
from jsonfallback.fields import FallbackJSONField
from phonenumber_field.modelfields import PhoneNumberField
from phonenumber_field.phonenumber import PhoneNumber
from phonenumbers import NumberParseException
@@ -378,12 +377,12 @@ class Order(LockModel, LoggedModel):
refund_sum=refund_sum_sq,
)
qs = qs.annotate(
computed_payment_refund_sum=Coalesce(payment_sum_sq, 0) - Coalesce(refund_sum_sq, 0),
computed_payment_refund_sum=Coalesce(payment_sum_sq, Decimal('0.00')) - Coalesce(refund_sum_sq, Decimal('0.00')),
)
qs = qs.annotate(
pending_sum_t=F('total') - Coalesce(payment_sum_sq, 0) + Coalesce(refund_sum_sq, 0),
pending_sum_rc=-1 * Coalesce(payment_sum_sq, 0) + Coalesce(refund_sum_sq, 0),
pending_sum_t=F('total') - Coalesce(payment_sum_sq, Decimal('0.00')) + Coalesce(refund_sum_sq, Decimal('0.00')),
pending_sum_rc=-1 * Coalesce(payment_sum_sq, Decimal('0.00')) + Coalesce(refund_sum_sq, Decimal('0.00')),
)
if refunds:
qs = qs.annotate(
@@ -394,23 +393,23 @@ class Order(LockModel, LoggedModel):
qs = qs.annotate(
is_overpaid=Case(
When(~Q(status=Order.STATUS_CANCELED) & Q(pending_sum_t__lt=-1e-8),
then=Value('1')),
then=Value(1)),
When(Q(status=Order.STATUS_CANCELED) & Q(pending_sum_rc__lt=-1e-8),
then=Value('1')),
default=Value('0'),
then=Value(1)),
default=Value(0),
output_field=models.IntegerField()
),
is_pending_with_full_payment=Case(
When(Q(status__in=(Order.STATUS_EXPIRED, Order.STATUS_PENDING)) & Q(pending_sum_t__lte=1e-8)
& Q(require_approval=False),
then=Value('1')),
default=Value('0'),
then=Value(1)),
default=Value(0),
output_field=models.IntegerField()
),
is_underpaid=Case(
When(Q(status=Order.STATUS_PAID) & Q(pending_sum_t__gt=1e-8),
then=Value('1')),
default=Value('0'),
then=Value(1)),
default=Value(0),
output_field=models.IntegerField()
)
)
@@ -1190,7 +1189,7 @@ class AbstractPosition(models.Model):
blank=True, null=True,
help_text=_("Empty, if this product is not an admission ticket")
)
attendee_name_parts = FallbackJSONField(
attendee_name_parts = models.JSONField(
blank=True, default=dict
)
attendee_email = models.EmailField(
@@ -2313,7 +2312,7 @@ class InvoiceAddress(models.Model):
is_business = models.BooleanField(default=False, verbose_name=_('Business customer'))
company = models.CharField(max_length=255, blank=True, verbose_name=_('Company name'))
name_cached = models.CharField(max_length=255, verbose_name=_('Full name'), blank=True)
name_parts = FallbackJSONField(default=dict)
name_parts = models.JSONField(default=dict)
street = models.TextField(verbose_name=_('Address'), blank=False)
zipcode = models.CharField(max_length=30, verbose_name=_('ZIP code'), blank=False)
city = models.CharField(max_length=255, verbose_name=_('City'), blank=False)

View File

@@ -26,7 +26,6 @@ from django.db import models, transaction
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _, pgettext_lazy
from django_scopes import ScopedManager
from jsonfallback.fields import FallbackJSONField
from phonenumber_field.modelfields import PhoneNumberField
from pretix.base.email import get_email_context
@@ -66,7 +65,7 @@ class WaitingListEntry(LoggedModel):
verbose_name=_("Name"),
blank=True, null=True,
)
name_parts = FallbackJSONField(
name_parts = models.JSONField(
blank=True, default=dict
)
email = models.EmailField(