Fix date parsing issue in Danish locale

This commit is contained in:
Raphael Michel
2020-02-19 18:00:02 +01:00
parent 2e5b80c83c
commit 6cd888a1dc

View File

@@ -1,3 +1,4 @@
from datetime import date, datetime, time
from decimal import Decimal from decimal import Decimal
from django import forms from django import forms
@@ -5,7 +6,7 @@ from django.conf import settings
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django.utils.timezone import now from django.utils.timezone import make_aware, now
from django.utils.translation import pgettext_lazy, ugettext_lazy as _ from django.utils.translation import pgettext_lazy, ugettext_lazy as _
from pretix.base.email import get_available_placeholders from pretix.base.email import get_available_placeholders
@@ -25,16 +26,17 @@ class ExtendForm(I18nModelForm):
'and you having sold more tickets than you planned!'), 'and you having sold more tickets than you planned!'),
required=False required=False
) )
expires = forms.DateField(
label=_("Expiration date"),
widget=forms.DateInput(attrs={
'class': 'datepickerfield',
'data-is-payment-date': 'true'
}),
)
class Meta: class Meta:
model = Order model = Order
fields = ['expires'] fields = []
widgets = {
'expires': forms.DateInput(attrs={
'class': 'datepickerfield',
'data-is-payment-date': 'true'
})
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@@ -45,11 +47,22 @@ class ExtendForm(I18nModelForm):
def clean(self): def clean(self):
data = super().clean() data = super().clean()
data['expires'] = data['expires'].replace(hour=23, minute=59, second=59) if data.get('expires'):
if data['expires'] < now(): if isinstance(data['expires'], date):
raise ValidationError(_('The new expiry date needs to be in the future.')) data['expires'] = make_aware(datetime.combine(
data['expires'],
time(hour=23, minute=59, second=59)
), self.instance.event.timezone)
else:
data['expires'] = data['expires'].replace(hour=23, minute=59, second=59)
if data['expires'] < now():
raise ValidationError(_('The new expiry date needs to be in the future.'))
return data return data
def save(self, commit=True):
self.instance.expires = self.cleaned_data['expires']
return super().save(commit)
class ConfirmPaymentForm(forms.Form): class ConfirmPaymentForm(forms.Form):
force = forms.BooleanField( force = forms.BooleanField(