From 6cd888a1dcdb31a5702d9df19621c5c941ae05b5 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 19 Feb 2020 18:00:02 +0100 Subject: [PATCH] Fix date parsing issue in Danish locale --- src/pretix/control/forms/orders.py | 35 ++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/pretix/control/forms/orders.py b/src/pretix/control/forms/orders.py index efb9557a47..31da079fa9 100644 --- a/src/pretix/control/forms/orders.py +++ b/src/pretix/control/forms/orders.py @@ -1,3 +1,4 @@ +from datetime import date, datetime, time from decimal import Decimal from django import forms @@ -5,7 +6,7 @@ from django.conf import settings from django.core.exceptions import ValidationError from django.db import models 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 pretix.base.email import get_available_placeholders @@ -25,16 +26,17 @@ class ExtendForm(I18nModelForm): 'and you having sold more tickets than you planned!'), required=False ) + expires = forms.DateField( + label=_("Expiration date"), + widget=forms.DateInput(attrs={ + 'class': 'datepickerfield', + 'data-is-payment-date': 'true' + }), + ) class Meta: model = Order - fields = ['expires'] - widgets = { - 'expires': forms.DateInput(attrs={ - 'class': 'datepickerfield', - 'data-is-payment-date': 'true' - }) - } + fields = [] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -45,11 +47,22 @@ class ExtendForm(I18nModelForm): def clean(self): data = super().clean() - 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.')) + if data.get('expires'): + if isinstance(data['expires'], date): + 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 + def save(self, commit=True): + self.instance.expires = self.cleaned_data['expires'] + return super().save(commit) + class ConfirmPaymentForm(forms.Form): force = forms.BooleanField(