mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
datetime: Move time zone to date time module
- It is more appropriate to have the time zone setting in date time module.
This commit is contained in:
1 parent
da3e92312c
commit
91eaf3301d
4 files changed
+67
-69
No files matched your search
@@ -21,6 +21,8 @@ Forms for configuring date and time
|
||||
|
||||
from django import forms
|
||||
from gettext import gettext as _
|
||||
import glob
|
||||
import re
|
||||
|
||||
|
||||
class DateTimeForm(forms.Form):
|
||||
@@ -28,3 +30,43 @@ class DateTimeForm(forms.Form):
|
||||
enabled = forms.BooleanField(
|
||||
label=_('Enable network time'),
|
||||
required=False)
|
||||
|
||||
time_zone = forms.ChoiceField(
|
||||
label=_('Time Zone'),
|
||||
help_text=_('Set your time zone to get accurate timestamps. \
|
||||
This will set the systemwide time zone.'))
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Initialize the date/time form."""
|
||||
forms.Form.__init__(self, *args, **kwargs)
|
||||
|
||||
time_zone_options = [(zone, zone)
|
||||
for zone in self.get_time_zones()]
|
||||
# Show not-set option only when time zone is not set
|
||||
if self.initial.get('time_zone') == 'none':
|
||||
time_zone_options.insert(0, ('none', _('-- no time zone set --')))
|
||||
|
||||
self.fields['time_zone'].choices = time_zone_options
|
||||
|
||||
@staticmethod
|
||||
def get_time_zones():
|
||||
"""Return list of available time zones"""
|
||||
time_zones = []
|
||||
for line in open('/usr/share/zoneinfo/zone.tab'):
|
||||
if re.match(r'^(#|\s*$)', line):
|
||||
continue
|
||||
|
||||
try:
|
||||
time_zones.append(line.split()[2])
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
time_zones.sort()
|
||||
|
||||
additional_time_zones = [
|
||||
path[len('/usr/share/zoneinfo/'):]
|
||||
for path in glob.glob('/usr/share/zoneinfo/Etc/*')]
|
||||
|
||||
# Add additional time zones at the top to make them more
|
||||
# noticeable because people won't look for them
|
||||
return additional_time_zones + time_zones
|
||||
Reference in new issue
Block a user