def _editor(self, context, **kwargs): result = super(DateTimeField, self)._editor(context, **kwargs) g = context.generator() result += g.button('...', id='%s-button' % kwargs['id'], type='button', cls='selection-invocation calendar-invocation', disabled=kwargs['disabled']) context.resource('prototype.js') context.resource('calendarview.js') context.resource('calendarview.css') locale_data = context.locale_data() js_values = dict( id=kwargs['id'], format=self.datetime_format(locale_data), today=context.localize(_(u"today")), day_names=g.js_value([ context.localize(lcg.week_day_name(i, abbrev=True)) for i in (6, 0, 1, 2, 3, 4, 5) ]), month_names=g.js_value( [context.localize(lcg.month_name(i)) for i in range(12)]), first_week_day=(locale_data.first_week_day + 1) % 7, ) result += g.script(""" Calendar.setup({dateField: '%(id)s', triggerElement: '%(id)s-button', dateFormat: '%(format)s'}); Calendar.TODAY = '%(today)s'; Calendar.SHORT_DAY_NAMES = %(day_names)s; Calendar.MONTH_NAMES = %(month_names)s; Calendar.FIRST_WEEK_DAY = %(first_week_day)d; """ % js_values) return result
def _editor(self, context, **kwargs): result = super(DateTimeField, self)._editor(context, **kwargs) g = context.generator() result += g.button('...', id='%s-button' % kwargs['id'], type='button', cls='selection-invocation calendar-invocation', disabled=kwargs['disabled']) context.resource('prototype.js') context.resource('calendarview.js') context.resource('calendarview.css') locale_data = context.locale_data() js_values = dict( id=kwargs['id'], format=self.datetime_format(locale_data), today=context.localize(_(u"today")), day_names=g.js_value([context.localize(lcg.week_day_name(i, abbrev=True)) for i in (6, 0, 1, 2, 3, 4, 5)]), month_names=g.js_value([context.localize(lcg.month_name(i)) for i in range(12)]), first_week_day=(locale_data.first_week_day + 1) % 7, ) result += g.script(""" Calendar.setup({dateField: '%(id)s', triggerElement: '%(id)s-button', dateFormat: '%(format)s'}); Calendar.TODAY = '%(today)s'; Calendar.SHORT_DAY_NAMES = %(day_names)s; Calendar.MONTH_NAMES = %(month_names)s; Calendar.FIRST_WEEK_DAY = %(first_week_day)d; """ % js_values) return result
def _localize(self, localizer): data = localizer.locale_data() dt = self._datetime displayed_timezone = "" if self._has_time and self._utc: timezone = localizer.timezone() or data.default_timezone if timezone is not None: dt = dt.astimezone(timezone) else: displayed_timezone = " UTC" result = dt.strftime(data.date_format) if not self._leading_zeros: result = self._LEADING_ZEROS.sub("", result) if self._has_time and self._show_time: time_format = self._show_seconds and data.exact_time_format or data.time_format result += " " + dt.strftime(time_format) if self._show_weekday: weekday = localizer.localize(lcg.week_day_name(dt.weekday(), abbrev=True)) result = weekday + " " + result return result + displayed_timezone
def _localize(self, localizer): dt = self._datetime data = localizer.locale_data() result = dt.strftime(data.date_format) if not self._leading_zeros: result = self._LEADING_ZEROS.sub('', result) if self._show_weekday: weekday = localizer.localize(lcg.week_day_name(dt.weekday(), abbrev=True)) result = weekday + ' ' + result if self._is_datetime: timezone = localizer.timezone() or data.default_timezone # TODO: Add tests for corner cases, such as all (dt.tzinfo, timezone, # self._show_time) combinations (in their existence or nonexistence). if dt.tzinfo and timezone: dt = dt.astimezone(timezone) if self._show_time: time_format = (self._show_seconds and data.exact_time_format or data.time_format) result += ' ' + dt.strftime(time_format) if not timezone and dt.tzinfo: result += ' ' + dt.tzinfo.tzname(dt) return result