示例#1
0
def first_weekday_setup(context):
    """Set the first day of the week based on the portal's locale.
    """
    reg = getUtility(IRegistry)
    settings = reg.forInterface(IEventSettings, prefix="plone.app.event")
    if settings.first_weekday is not None:
        # don't overwrite if it's already set
        return

    first = 6
    try:
        site = getSite()
        # find the locale implied by the portal's language
        language = site.Language()
        parts = (language.split('-') + [None, None])[:3]
        locale = locales.getLocale(*parts)
        # look up first day of week
        gregorian_calendar = locale.dates.calendars.get(u'gregorian', None)
        if gregorian_calendar is not None:
            first = wkday_to_mon0(gregorian_calendar.week.get('firstDay', 7))
    except LoadLocaleError:
        # If we cannot get the locale, just Sunday as first weekday
        pass
    # save setting
    settings.first_weekday = first
示例#2
0
def first_weekday_setup(context):
    """Set the first day of the week based on the portal's locale.
    """
    reg = getUtility(IRegistry)
    settings = reg.forInterface(IEventSettings, prefix="plone.app.event")
    if settings.first_weekday is not None:
        # don't overwrite if it's already set
        return

    first = 6
    try:
        site = getSite()
        # find the locale implied by the portal's language
        language = site.Language()
        parts = (language.split('-') + [None, None])[:3]
        locale = locales.getLocale(*parts)
        # look up first day of week
        gregorian_calendar = locale.dates.calendars.get(u'gregorian', None)
        if gregorian_calendar is not None:
            first = wkday_to_mon0(gregorian_calendar.week.get('firstDay', 7))
    except LoadLocaleError:
        # If we cannot get the locale, just Sunday as first weekday
        pass
    # save setting
    settings.first_weekday = first
示例#3
0
 def test_wkday_to_mon0(self):
     from plone.app.event.base import wkday_to_mon0
     li = [wkday_to_mon0(day) for day in range(0, 7)]
     self.assertEqual(li, [6, 0, 1, 2, 3, 4, 5])