For backend date/time fields, always show which timezone is used
authorMagnus Hagander <[email protected]>
Tue, 3 Dec 2024 20:30:15 +0000 (21:30 +0100)
committerMagnus Hagander <[email protected]>
Tue, 3 Dec 2024 20:30:15 +0000 (21:30 +0100)
postgresqleu/util/backendforms.py

index c796b14515e849399a1403ad382384d2c8743eec..f70c67d564b4d2ff347c95dac993e9bf29221749 100644 (file)
@@ -1,6 +1,7 @@
 import django.forms
 import django.forms.widgets
 from django.core.validators import MinValueValidator, MaxValueValidator
+from django.conf import settings
 
 from postgresqleu.util.forms import ConcurrentProtectedModelForm
 from postgresqleu.util.widgets import HtmlDateInput
@@ -122,6 +123,13 @@ class BackendForm(ConcurrentProtectedModelForm):
                         MinValueValidator(self.conference.startdate),
                         MaxValueValidator(self.conference.enddate),
                     ])
+            if isinstance(v, (django.forms.fields.DateTimeField, django.forms.fields.DateField, django.forms.fields.TimeField, django.contrib.postgres.forms.ranges.DateTimeRangeField)):
+                t = getattr(v, 'help_text', '')
+                if t:
+                    if not t.endswith('.'):
+                        t = t + '.'
+                    t = t + ' '
+                v.help_text = t + 'Time specified in timezone {}.'.format(self.conference.tzname if self.conference else settings.TIME_ZONE)
 
         for field, vattype in list(self.vat_fields.items()):
             self.fields[field].widget.attrs['class'] = 'backend-vat-field backend-vat-{0}-field'.format(vattype)