Source code for superdjango.contrib.i18n.timezones.models

# Imports

from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _
from solo.models import SingletonModel
from .choices import ALL_TIMEZONE_CHOICES, AFRICAN_TIMEZONE_CHOICES, ASIAN_TIMEZONE_CHOICES, \
    AUSTRALIAN_TIMEZONE_CHOICES, CANADIAN_TIMEZONE_CHOICES, CENTRAL_AMERICAN_TIMEZONE_CHOICES, \
    EUROPEAN_TIMEZONE_CHOICES, MEXICAN_TIMEZONE_CHOICES, MIDDLE_EASTERN_TIMEZONE_CHOICES, \
    SOUTH_AMERICAN_TIMEZONE_CHOICES, US_TIMEZONE_CHOICES

# Exports

__all__ = (
    "TimeZoneSettingsModel",
)

# Models


[docs]class TimeZoneSettingsModel(SingletonModel): """Manage the availability of time zones.""" default_timezone = models.CharField( _("default time zone"), blank=True, choices=ALL_TIMEZONE_CHOICES, help_text=_("The default time zone."), max_length=128, null=True ) # Remaining flag fields in alphabetical order. african_enabled = models.BooleanField( _("African time zones"), default=True, help_text=_("Indicates African time zones are enabled.") ) asian_enabled = models.BooleanField( _("Asian time zones"), default=True, help_text=_("Indicates Asian time zones are enabled.") ) australian_enabled = models.BooleanField( _("Australian time zones"), default=True, help_text=_("Indicates Australian time zones are enabled.") ) canadian_enabled = models.BooleanField( _("Canadian time zones"), default=True, help_text=_("Indicates Canadian time zones are enabled.") ) central_american_enabled = models.BooleanField( _("Central American time zones"), default=True, help_text=_("Indicates Central American time zones are enabled. Includes the Caribbean.") ) european_enabled = models.BooleanField( _("European time zones"), default=True, help_text=_("Indicates European time zones are enabled.") ) mexican_enabled = models.BooleanField( _("Mexican time zones"), default=True, help_text=_("Indicates U.S. time zones are enabled.") ) middle_eastern_enabled = models.BooleanField( _("Middle Eastern time zones"), default=True, help_text=_("Indicates Middle Eastern time zones are enabled.") ) south_american_enabled = models.BooleanField( _("South American time zones"), default=True, help_text=_("Indicates South American time zones are enabled.") ) us_enabled = models.BooleanField( _("United States time zones"), default=True, help_text=_("Indicates U.S. time zones are enabled.") ) class Meta: abstract = True def __str__(self): return str(_("Time Zone Settings"))
[docs] def get_timezone_choices(self): """Get the collective time zone choices available to users. :rtype: list """ choices = [(settings.TIME_ZONE, settings.TIME_ZONE)] if self.african_enabled: choices += AFRICAN_TIMEZONE_CHOICES if self.asian_enabled: choices += ASIAN_TIMEZONE_CHOICES if self.australian_enabled: choices += AUSTRALIAN_TIMEZONE_CHOICES if self.canadian_enabled: choices += CANADIAN_TIMEZONE_CHOICES if self.central_american_enabled: choices += CENTRAL_AMERICAN_TIMEZONE_CHOICES if self.european_enabled: choices += EUROPEAN_TIMEZONE_CHOICES if self.mexican_enabled: choices += MEXICAN_TIMEZONE_CHOICES if self.middle_eastern_enabled: choices += MIDDLE_EASTERN_TIMEZONE_CHOICES if self.south_american_enabled: choices += SOUTH_AMERICAN_TIMEZONE_CHOICES if self.us_enabled: choices += US_TIMEZONE_CHOICES return choices
def _get_sections(self): return [ "superdjango", ] def _get_items(self, section): if section == "superdjango": return [ ("timezones_default", self.default_timezone), ("timezones_african_enabled", self.african_enabled), ("timezones_asian_enabled", self.asian_enabled), ("timezones_australian_enabled", self.australian_enabled), ("timezones_canadian_enabled", self.canadian_enabled), ("timezones_central_american_enabled", self.central_american_enabled), ("timezones_european_enabled", self.european_enabled), ("timezones_mexican_enabled", self.mexican_enabled), ("timezones_middle_eastern_enabled", self.middle_eastern_enabled), ("timezones_south_american_enabled", self.south_american_enabled), ("timezones_us_enabled", self.south_american_enabled), ] else: return list()