Skip to content
Snippets Groups Projects
Commit a393934e authored by jan.bednarik's avatar jan.bednarik
Browse files

Fix election edit datetime input

parent 9b7768ac
No related branches found
No related tags found
2 merge requests!8Fix election edit datetime input,!7Fix election edit datetime input
Pipeline #4961 passed
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
Forms for Helios Forms for Helios
""" """
import pytz
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.utils.timezone import make_aware, make_naive
from .fields import SplitDateTimeField from .fields import SplitDateTimeField
from .models import Election from .models import Election
...@@ -27,7 +30,15 @@ class ElectionForm(forms.Form): ...@@ -27,7 +30,15 @@ class ElectionForm(forms.Form):
if settings.ALLOW_ELECTION_INFO_URL: if settings.ALLOW_ELECTION_INFO_URL:
election_info_url = forms.CharField(required=False, initial="", label=u"URL pro stažení informací o hlasování", help_text=u"URL dokumentu ve formátu PDF, obsahujícího doplňkové informace k hlasování, např. životopisy a profily kandidátů") election_info_url = forms.CharField(required=False, initial="", label=u"URL pro stažení informací o hlasování", help_text=u"URL dokumentu ve formátu PDF, obsahujícího doplňkové informace k hlasování, např. životopisy a profily kandidátů")
pass def __init__(self, data=None, *args, **kwargs):
# v DB se ukládá naivní UTC, ale do formuláře potřebujeme převést zpět na Europe/Prague
if data:
tz = pytz.timezone("Europe/Prague")
if "voting_starts_at" in data:
data["voting_starts_at"] = make_naive(make_aware(data["voting_starts_at"], pytz.UTC), tz)
if "voting_ends_at" in data:
data["voting_ends_at"] = make_naive(make_aware(data["voting_ends_at"], pytz.UTC), tz)
super().__init__(data, *args, **kwargs)
class ElectionTimeExtensionForm(forms.Form): class ElectionTimeExtensionForm(forms.Form):
voting_extended_until = SplitDateTimeField(help_text = u'datum a čas prodlouženého ukončení hlasování; v lokálním čase!', voting_extended_until = SplitDateTimeField(help_text = u'datum a čas prodlouženého ukončení hlasování; v lokálním čase!',
......
...@@ -95,16 +95,17 @@ class SelectTimeWidget(Widget): ...@@ -95,16 +95,17 @@ class SelectTimeWidget(Widget):
self.meridiem_val = 'a.m.' self.meridiem_val = 'a.m.'
else: else:
self.meridiem_val = None self.meridiem_val = None
# If we're doing a 12-hr clock, there will be a meridiem value, so make sure the # If we're doing a 12-hr clock, there will be a meridiem value, so make sure the
# hours get printed correctly # hours get printed correctly
if self.twelve_hr and self.meridiem_val: if self.twelve_hr and self.meridiem_val:
if self.meridiem_val.lower().startswith('p') and hour_val > 12 and hour_val < 24: if self.meridiem_val.lower().startswith('p') and hour_val > 12 and hour_val < 24:
hour_val = hour_val % 12 hour_val = hour_val % 12
elif hour_val == 0: # BUG this breaks 24h clock on 0 hours
hour_val = 12 # elif hour_val == 0:
# hour_val = 12
output = [] output = []
if 'id' in self.attrs: if 'id' in self.attrs:
id_ = self.attrs['id'] id_ = self.attrs['id']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment