def default_timezone(context=None): """Return the timezone from the portal or user. :param context: Optional context. If not given, the current Site is used. :type context: Content object :returns: Timezone identifier. :rtype: string """ # TODO: test member timezone if not context: context = getSite() membership = getToolByName(context, 'portal_membership', None) if membership and not membership.isAnonymousUser(): # the user has not logged in member = membership.getAuthenticatedMember() member_timezone = member.getProperty('timezone', None) if member_timezone: return pytz.timezone(member_timezone).zone portal_timezone = None reg = queryUtility(IRegistry, context=context, default=None) if reg: portal_timezone= reg.forInterface( IEventSettings, prefix="plone.app.event").portal_timezone # fallback to what plone.event is doing if not portal_timezone: portal_timezone = fallback_default_timezone() if portal_timezone in replacement_zones.keys(): portal_timezone = replacement_zones[portal_timezone] portal_timezone = validated_timezone(portal_timezone, FALLBACK_TIMEZONE) return portal_timezone
class IEventSettings(Interface): """Global Controlpanel settings for eventish content types. """ portal_timezone = schema.Choice( title=_(u"Portal default timezone"), description=_(u"help_portal_timezone", default=u"The timezone setting of the portal. Users can set " "their own timezone, if available timezones are defined."), required=True, default=fallback_default_timezone(), vocabulary="plone.app.event.Timezones" ) available_timezones = schema.List( title=_(u"Available timezones"), description=_(u"help_available_timezones", default=u"The timezones, which should be available for the portal. " "Can be set for users and events"), required=False, default=[], value_type=schema.Choice( vocabulary="plone.app.event.Timezones" ) ) first_weekday = schema.Choice( title=_(u'label_first_weekday', default=u'First Weekday'), description=_(u'help_first_weekday', default=u'First day in the Week.'), required=True, default='0', vocabulary="plone.app.event.Weekdays" )
def default_timezone(context=None, as_tzinfo=False): """Return the timezone from the portal or user. :param context: Optional context. If not given, the current Site is used. :type context: Content object :param as_tzinfo: Return the default timezone as tzinfo object. :type as_tzinfo: boolean :returns: Timezone identifier or tzinfo object. :rtype: string or tzinfo object """ # TODO: test member timezone if not context: context = getSite() membership = getToolByName(context, 'portal_membership', None) if membership and not membership.isAnonymousUser(): # user not logged in member = membership.getAuthenticatedMember() member_timezone = member.getProperty('timezone', None) if member_timezone: info = pytz.timezone(member_timezone) return info if as_tzinfo else info.zone portal_timezone = None reg = queryUtility(IRegistry, context=context, default=None) if reg: portal_timezone = reg.forInterface( IEventSettings, prefix="plone.app.event", check=False # Don't fail, if portal_timezone isn't set. ).portal_timezone # fallback to what plone.event is doing if not portal_timezone: portal_timezone = fallback_default_timezone() # Change any ambiguous timezone abbreviations to their most common # non-ambigious timezone name. if portal_timezone in replacement_zones.keys(): portal_timezone = replacement_zones[portal_timezone] portal_timezone = validated_timezone(portal_timezone, FALLBACK_TIMEZONE) if as_tzinfo: return pytz.timezone(portal_timezone) return portal_timezone
def default_timezone(context=None, as_tzinfo=False): """Return the timezone from the portal or user. :param context: Optional context. If not given, the current Site is used. :type context: Content object :param as_tzinfo: Return the default timezone as tzinfo object. :type as_tzinfo: boolean :returns: Timezone identifier or tzinfo object. :rtype: string or tzinfo object """ # TODO: test member timezone if not context: context = getSite() membership = getToolByName(context, 'portal_membership', None) if membership and not membership.isAnonymousUser(): # user not logged in member = membership.getAuthenticatedMember() member_timezone = member.getProperty('timezone', None) if member_timezone: return pytz.timezone(member_timezone).zone portal_timezone = None reg = queryUtility(IRegistry, context=context, default=None) if reg: try: portal_timezone = reg.forInterface( IEventSettings, prefix="plone.app.event").portal_timezone except KeyError: # plone.registry warns that registry settings can not be # available or valid pass # fallback to what plone.event is doing if not portal_timezone: portal_timezone = fallback_default_timezone() # Change any ambiguous timezone abbreviations to their most common # non-ambigious timezone name. if portal_timezone in replacement_zones.keys(): portal_timezone = replacement_zones[portal_timezone] portal_timezone = validated_timezone(portal_timezone, FALLBACK_TIMEZONE) if as_tzinfo: return pytz.timezone(portal_timezone) return portal_timezone
def default_timezone(context=None, as_tzinfo=False): """Return the timezone from the portal or user. :param context: Optional context. If not given, the current Site is used. :type context: Content object :param as_tzinfo: Return the default timezone as tzinfo object. :type as_tzinfo: boolean :returns: Timezone identifier or tzinfo object. :rtype: string or tzinfo object """ # TODO: test member timezone if not context: context = getSite() membership = getToolByName(context, 'portal_membership', None) if membership and not membership.isAnonymousUser(): # user not logged in member = membership.getAuthenticatedMember() member_timezone = member.getProperty('timezone', None) if member_timezone: info = pytz.timezone(member_timezone) return info if as_tzinfo else info.zone reg_key = 'plone.portal_timezone' registry = getUtility(IRegistry) portal_timezone = registry.get(reg_key, None) # fallback to what plone.event is doing if not portal_timezone: portal_timezone = fallback_default_timezone() # Change any ambiguous timezone abbreviations to their most common # non-ambigious timezone name. if portal_timezone in replacement_zones.keys(): portal_timezone = replacement_zones[portal_timezone] portal_timezone = validated_timezone(portal_timezone, FALLBACK_TIMEZONE) if as_tzinfo: return pytz.timezone(portal_timezone) return portal_timezone
def default_timezone(context=None): """ Retrieve the timezone from the portal or user. TODO: test member timezone """ if context: membership = getToolByName(context, 'portal_membership') if not membership.isAnonymousUser(): # the user has not logged in member = membership.getAuthenticatedMember() member_timezone = member.getProperty('timezone', None) if member_timezone: return pytz.timezone(member_timezone).zone controlpanel = getUtility(IRegistry).forInterface(IEventSettings, prefix="plone.app.event") portal_timezone = controlpanel.portal_timezone # fallback to what plone.event is doing if not portal_timezone: return fallback_default_timezone() # following statement ensures, that timezone is a valid pytz zone return pytz.timezone(portal_timezone).zone