mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-05-05 13:21:49 +02:00
Fix timezone usage in grouped_order form update
This commit is contained in:
parent
0a227d5723
commit
17dbba9cc8
1 changed files with 8 additions and 4 deletions
|
@ -4,6 +4,7 @@ from django import forms
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.core.exceptions import NON_FIELD_ERRORS, ValidationError
|
from django.core.exceptions import NON_FIELD_ERRORS, ValidationError
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
from la_chariotte import settings
|
from la_chariotte import settings
|
||||||
from la_chariotte.order.models import GroupedOrder, Item
|
from la_chariotte.order.models import GroupedOrder, Item
|
||||||
|
@ -52,9 +53,11 @@ class GroupedOrderForm(forms.ModelForm):
|
||||||
|
|
||||||
# When updating an existing order, reuse existing values
|
# When updating an existing order, reuse existing values
|
||||||
if kwargs["instance"]:
|
if kwargs["instance"]:
|
||||||
self.initial["deadline_date"] = self.instance.deadline.date()
|
locale_deadline = self.instance.deadline.replace(
|
||||||
self.initial["deadline_time"] = self.instance.deadline.time()
|
tzinfo=timezone.utc
|
||||||
# TODO: there is a bug here ; the time displayed in form is 2 hours earlier than the actual deadline time
|
).astimezone(tz=None)
|
||||||
|
self.initial["deadline_date"] = locale_deadline.date()
|
||||||
|
self.initial["deadline_time"] = locale_deadline.time()
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
self.instance.orga = get_user_model().objects.get(id=self.user.pk)
|
self.instance.orga = get_user_model().objects.get(id=self.user.pk)
|
||||||
|
@ -62,9 +65,10 @@ class GroupedOrderForm(forms.ModelForm):
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
cleaned_data = self.cleaned_data
|
cleaned_data = self.cleaned_data
|
||||||
self.instance.deadline = datetime.datetime.combine(
|
deadline = datetime.datetime.combine(
|
||||||
self.cleaned_data["deadline_date"], self.cleaned_data["deadline_time"]
|
self.cleaned_data["deadline_date"], self.cleaned_data["deadline_time"]
|
||||||
)
|
)
|
||||||
|
self.instance.deadline = timezone.make_aware(deadline)
|
||||||
return cleaned_data
|
return cleaned_data
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue