Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Imports
3from django.conf import settings
4from django.db import models
5from django.utils.translation import ugettext_lazy as _
6from solo.models import SingletonModel
7from .choices import ALL_TIMEZONE_CHOICES, AFRICAN_TIMEZONE_CHOICES, ASIAN_TIMEZONE_CHOICES, \
8 AUSTRALIAN_TIMEZONE_CHOICES, CANADIAN_TIMEZONE_CHOICES, CENTRAL_AMERICAN_TIMEZONE_CHOICES, \
9 EUROPEAN_TIMEZONE_CHOICES, MEXICAN_TIMEZONE_CHOICES, MIDDLE_EASTERN_TIMEZONE_CHOICES, \
10 SOUTH_AMERICAN_TIMEZONE_CHOICES, US_TIMEZONE_CHOICES
12# Exports
14__all__ = (
15 "TimeZoneSettingsModel",
16)
18# Models
21class TimeZoneSettingsModel(SingletonModel):
22 """Manage the availability of time zones."""
24 default_timezone = models.CharField(
25 _("default time zone"),
26 blank=True,
27 choices=ALL_TIMEZONE_CHOICES,
28 help_text=_("The default time zone."),
29 max_length=128,
30 null=True
31 )
33 # Remaining flag fields in alphabetical order.
35 african_enabled = models.BooleanField(
36 _("African time zones"),
37 default=True,
38 help_text=_("Indicates African time zones are enabled.")
39 )
41 asian_enabled = models.BooleanField(
42 _("Asian time zones"),
43 default=True,
44 help_text=_("Indicates Asian time zones are enabled.")
45 )
47 australian_enabled = models.BooleanField(
48 _("Australian time zones"),
49 default=True,
50 help_text=_("Indicates Australian time zones are enabled.")
51 )
53 canadian_enabled = models.BooleanField(
54 _("Canadian time zones"),
55 default=True,
56 help_text=_("Indicates Canadian time zones are enabled.")
57 )
59 central_american_enabled = models.BooleanField(
60 _("Central American time zones"),
61 default=True,
62 help_text=_("Indicates Central American time zones are enabled. Includes the Caribbean.")
63 )
65 european_enabled = models.BooleanField(
66 _("European time zones"),
67 default=True,
68 help_text=_("Indicates European time zones are enabled.")
69 )
71 mexican_enabled = models.BooleanField(
72 _("Mexican time zones"),
73 default=True,
74 help_text=_("Indicates U.S. time zones are enabled.")
75 )
77 middle_eastern_enabled = models.BooleanField(
78 _("Middle Eastern time zones"),
79 default=True,
80 help_text=_("Indicates Middle Eastern time zones are enabled.")
81 )
83 south_american_enabled = models.BooleanField(
84 _("South American time zones"),
85 default=True,
86 help_text=_("Indicates South American time zones are enabled.")
87 )
89 us_enabled = models.BooleanField(
90 _("United States time zones"),
91 default=True,
92 help_text=_("Indicates U.S. time zones are enabled.")
93 )
95 class Meta:
96 abstract = True
98 def __str__(self):
99 return str(_("Time Zone Settings"))
101 def get_timezone_choices(self):
102 """Get the collective time zone choices available to users.
104 :rtype: list
106 """
107 choices = [(settings.TIME_ZONE, settings.TIME_ZONE)]
109 if self.african_enabled:
110 choices += AFRICAN_TIMEZONE_CHOICES
112 if self.asian_enabled:
113 choices += ASIAN_TIMEZONE_CHOICES
115 if self.australian_enabled:
116 choices += AUSTRALIAN_TIMEZONE_CHOICES
118 if self.canadian_enabled:
119 choices += CANADIAN_TIMEZONE_CHOICES
121 if self.central_american_enabled:
122 choices += CENTRAL_AMERICAN_TIMEZONE_CHOICES
124 if self.european_enabled:
125 choices += EUROPEAN_TIMEZONE_CHOICES
127 if self.mexican_enabled:
128 choices += MEXICAN_TIMEZONE_CHOICES
130 if self.middle_eastern_enabled:
131 choices += MIDDLE_EASTERN_TIMEZONE_CHOICES
133 if self.south_american_enabled:
134 choices += SOUTH_AMERICAN_TIMEZONE_CHOICES
136 if self.us_enabled:
137 choices += US_TIMEZONE_CHOICES
139 return choices
141 def _get_sections(self):
142 return [
143 "superdjango",
144 ]
146 def _get_items(self, section):
147 if section == "superdjango":
148 return [
149 ("timezones_default", self.default_timezone),
150 ("timezones_african_enabled", self.african_enabled),
151 ("timezones_asian_enabled", self.asian_enabled),
152 ("timezones_australian_enabled", self.australian_enabled),
153 ("timezones_canadian_enabled", self.canadian_enabled),
154 ("timezones_central_american_enabled", self.central_american_enabled),
155 ("timezones_european_enabled", self.european_enabled),
156 ("timezones_mexican_enabled", self.mexican_enabled),
157 ("timezones_middle_eastern_enabled", self.middle_eastern_enabled),
158 ("timezones_south_american_enabled", self.south_american_enabled),
159 ("timezones_us_enabled", self.south_american_enabled),
160 ]
161 else:
162 return list()