Hide keyboard shortcuts

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 

2 

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 

11 

12# Exports 

13 

14__all__ = ( 

15 "TimeZoneSettingsModel", 

16) 

17 

18# Models 

19 

20 

21class TimeZoneSettingsModel(SingletonModel): 

22 """Manage the availability of time zones.""" 

23 

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 ) 

32 

33 # Remaining flag fields in alphabetical order. 

34 

35 african_enabled = models.BooleanField( 

36 _("African time zones"), 

37 default=True, 

38 help_text=_("Indicates African time zones are enabled.") 

39 ) 

40 

41 asian_enabled = models.BooleanField( 

42 _("Asian time zones"), 

43 default=True, 

44 help_text=_("Indicates Asian time zones are enabled.") 

45 ) 

46 

47 australian_enabled = models.BooleanField( 

48 _("Australian time zones"), 

49 default=True, 

50 help_text=_("Indicates Australian time zones are enabled.") 

51 ) 

52 

53 canadian_enabled = models.BooleanField( 

54 _("Canadian time zones"), 

55 default=True, 

56 help_text=_("Indicates Canadian time zones are enabled.") 

57 ) 

58 

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 ) 

64 

65 european_enabled = models.BooleanField( 

66 _("European time zones"), 

67 default=True, 

68 help_text=_("Indicates European time zones are enabled.") 

69 ) 

70 

71 mexican_enabled = models.BooleanField( 

72 _("Mexican time zones"), 

73 default=True, 

74 help_text=_("Indicates U.S. time zones are enabled.") 

75 ) 

76 

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 ) 

82 

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 ) 

88 

89 us_enabled = models.BooleanField( 

90 _("United States time zones"), 

91 default=True, 

92 help_text=_("Indicates U.S. time zones are enabled.") 

93 ) 

94 

95 class Meta: 

96 abstract = True 

97 

98 def __str__(self): 

99 return str(_("Time Zone Settings")) 

100 

101 def get_timezone_choices(self): 

102 """Get the collective time zone choices available to users. 

103 

104 :rtype: list 

105 

106 """ 

107 choices = [(settings.TIME_ZONE, settings.TIME_ZONE)] 

108 

109 if self.african_enabled: 

110 choices += AFRICAN_TIMEZONE_CHOICES 

111 

112 if self.asian_enabled: 

113 choices += ASIAN_TIMEZONE_CHOICES 

114 

115 if self.australian_enabled: 

116 choices += AUSTRALIAN_TIMEZONE_CHOICES 

117 

118 if self.canadian_enabled: 

119 choices += CANADIAN_TIMEZONE_CHOICES 

120 

121 if self.central_american_enabled: 

122 choices += CENTRAL_AMERICAN_TIMEZONE_CHOICES 

123 

124 if self.european_enabled: 

125 choices += EUROPEAN_TIMEZONE_CHOICES 

126 

127 if self.mexican_enabled: 

128 choices += MEXICAN_TIMEZONE_CHOICES 

129 

130 if self.middle_eastern_enabled: 

131 choices += MIDDLE_EASTERN_TIMEZONE_CHOICES 

132 

133 if self.south_american_enabled: 

134 choices += SOUTH_AMERICAN_TIMEZONE_CHOICES 

135 

136 if self.us_enabled: 

137 choices += US_TIMEZONE_CHOICES 

138 

139 return choices 

140 

141 def _get_sections(self): 

142 return [ 

143 "superdjango", 

144 ] 

145 

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()