def test_get_month_names(): set_locale(Locale('en', 'US')) assert i18n.get_month_names('wide')[1] == 'January' set_locale(Locale('es')) assert i18n.get_month_names('abbreviated')[1] == 'ene.' set_locale(Locale('de', 'DE')) assert i18n.get_month_names('narrow', context='stand-alone')[1] == 'J'
def get_title(self, sheet_name, date): # date information month_name = get_month_names()[date.month].upper() week_number = date.strftime('%U') # format the string return _(u'%s - %s - Week %s') % (sheet_name, month_name, week_number)
def test_get_month_names(): assert i18n.get_month_names() == {1: u'janvier', 2: u'février', 3: u'mars', 4: u'avril', 5: u'mai', 6: u'juin', 7: u'juillet', 8: u'août', 9: u'septembre', 10: u'octobre', 11: u'novembre', 12: u'décembre'} assert i18n.get_month_names(width='wide') == {1: u'janvier', 2: u'février', 3: u'mars', 4: u'avril', 5: u'mai', 6: u'juin', 7: u'juillet', 8: u'août', 9: u'septembre', 10: u'octobre', 11: u'novembre', 12: u'décembre'} assert i18n.get_month_names(width='abbreviated') == {1: u'janv.', 2: u'févr.', 3: u'mars', 4: u'avr.', 5: u'mai', 6: u'juin', 7: u'juil.', 8: u'août', 9: u'sept.', 10: u'oct.', 11: u'nov.', 12: u'déc.'} assert i18n.get_month_names(width='narrow') == {1: u'J', 2: u'F', 3: u'M', 4: u'A', 5: u'M', 6: u'J', 7: u'J', 8: u'A', 9: u'S', 10: u'O', 11: u'N', 12: u'D'}
def test_get_month_names(): assert i18n.get_month_names() == {1: u'janvier', 2: u'f\xe9vrier', 3: u'mars', 4: u'avril', 5: u'mai', 6: u'juin', 7: u'juillet', 8: u'ao\xfbt', 9: u'septembre', 10: u'octobre', 11: u'novembre', 12: u'd\xe9cembre'} assert i18n.get_month_names(width='wide') == {1: u'janvier', 2: u'f\xe9vrier', 3: u'mars', 4: u'avril', 5: u'mai', 6: u'juin', 7: u'juillet', 8: u'ao\xfbt', 9: u'septembre', 10: u'octobre', 11: u'novembre', 12: u'd\xe9cembre'} assert i18n.get_month_names(width='abbreviated') == {1: u'janv.', 2: u'f\xe9vr.', 3: u'mars', 4: u'avr.', 5: u'mai', 6: u'juin', 7: u'juil.', 8: u'ao\xfbt', 9: u'sept.', 10: u'oct.', 11: u'nov.', 12: u'd\xe9c.'} assert i18n.get_month_names(width='narrow') == {1: u'J', 2: u'F', 3: u'M', 4: u'A', 5: u'M', 6: u'J', 7: u'J', 8: u'A', 9: u'S', 10: u'O', 11: u'N', 12: u'D'}
def render(self, h, comp, *args): # id used for this calendar component container_id = h.generate_id('calendar-') # container for the date picker table h << h.div(id=container_id, class_='calendar') # javascript code # hack for an IE javascript bug: declare a global variable in the head h << h.head.javascript('%s-var' % self.var, "var %s = null;" % self.var) days_order = (6, 0, 1, 2, 3, 4, 5) weekdays_1char = [get_day_names('narrow')[i].title() for i in days_order] weekdays_short = [get_day_names('abbreviated')[i][:2].title() for i in days_order] weekdays_medium = [get_day_names('abbreviated')[i].title() for i in days_order] weekdays_long = [get_day_names('wide')[i].title() for i in days_order] months_order = range(1, 13) months_short = [get_month_names('abbreviated')[i].title() for i in months_order] months_long = [get_month_names('wide')[i].title() for i in months_order] js = u""" // WARNING: we should never try to parse a date string because it's format depend on the locale! // calendar %(var)s = new YAHOO.widget.Calendar("%(container_id)s", { title:%(title)s, mindate:%(mindate)s, maxdate:%(maxdate)s, start_weekday:1, locale_weekdays:"short", close:%(close_button)s } ); // the "selected" config property does not accept Date objects, so we call the "select" function instead %(var)s.select(%(curdate)s); // date labels for the calendar display %(var)s.cfg.setProperty("WEEKDAYS_1CHAR", %(weekdays_1char)s); %(var)s.cfg.setProperty("WEEKDAYS_SHORT", %(weekdays_short)s); %(var)s.cfg.setProperty("WEEKDAYS_MEDIUM",%(weekdays_medium)s); %(var)s.cfg.setProperty("WEEKDAYS_LONG", %(weekdays_long)s); %(var)s.cfg.setProperty("MONTHS_SHORT", %(months_short)s); %(var)s.cfg.setProperty("MONTHS_LONG", %(months_long)s); // on select handler function on_%(var)s_select(type,args,obj) { var dateElements = args[0][0]; var date = new Date(dateElements[0], dateElements[1]-1, dateElements[2]); var format = %(field_format)s; var field = document.getElementById(%(field_id)s); field.value = formatDate(date, format); if (%(close_on_select)s) { %(var)s.hide(); } %(on_select)s; } // register the handler and renders the calendar %(var)s.selectEvent.subscribe(on_%(var)s_select, %(var)s, true); %(var)s.render(); """ % dict(var=self.var, container_id=container_id, field_id=json.dumps(self.field_id), field_format=json.dumps(self.field_format), title=json.dumps(self.title), close_button=json.dumps(self.close_button), close_on_select=json.dumps(self.close_on_select), on_select=self.on_select, curdate=js_datetime(self.curdate), mindate=js_datetime(self.mindate), maxdate=js_datetime(self.maxdate), weekdays_1char=json.dumps(weekdays_1char), weekdays_short=json.dumps(weekdays_short), weekdays_medium=json.dumps(weekdays_medium), weekdays_long=json.dumps(weekdays_long), months_short=json.dumps(months_short), months_long=json.dumps(months_long)) h << h.script(js, type='text/javascript') return h.root
def render_async(self, h, comp, *args): with h.div(class_='calendar-input'): input_id = h.generate_id('input') calendar_id = h.generate_id('calendar') if self.is_hidden: style = 'display: none;' else: style = 'display: block;' with h.div(class_='calendar', id_=calendar_id, style=style): with h.div(class_='calendar-header'): with h.a(title=_(u'Previous')).action(self.previous_month): h << h.i(class_='icon-arrow-left icon-grey', title=_(u'Previous')) with h.span(class_='current'): with h.select(onchange=ajax.Update(action=self.change_month)): for n, month in i18n.get_month_names().iteritems(): month = month.capitalize() h << h.option(month, value=n).selected(self.current.month) h << u' ' with h.select(onchange=ajax.Update(action=self.change_year)): for year in xrange(self.current.year - YEARS_AROUND, self.current.year + YEARS_AROUND): h << h.option(year, value=year).selected(self.current.year) with h.a(title=_(u'Next')).action(self.next_month): h << h.i(class_='icon-arrow-right icon-grey', title=_(u'Next')) with h.div(class_='calendar-content'): if isinstance(self.date, date): if self.current.year == self.date.year and self.current.month == self.date.month: active = self.date.day else: active = -1 else: active = -1 today = date.today() if today.month == self.current.month and today.year == self.current.year: today = today.day else: today = -1 with h.table: with h.thead: with h.tr: days = [day.capitalize() for day in i18n.get_day_names().itervalues()] h << [h.th(h.span(d[:2], title=d)) for d in days] with h.tbody: for line in calendar.monthcalendar(self.current.year, self.current.month): with h.tr: for day in line: if day == 0: h << h.td(class_='not-this-month') else: authorized = self.is_authorized_date(self.current.replace(day=day)) cls = [] if day == active: cls.append(u'active') if day == today: cls.append(u'today') if not authorized: cls.append(u'excluded') with h.td(class_=' '.join(cls)): if authorized: h << h.a(day).action(lambda day=day: self.choose_date(day, comp)) else: h << h.span(day) with h.div(class_='calendar-today'): h << h.a(h.i(class_='icon-calendar icon-grey'), _(u"Today"), class_='today-link btn').action(self.set_today) if self.allow_none: h << h.a(h.i(class_='icon-remove icon-grey'), _(u'None'), class_='erase btn').action(lambda: self.remove_date(comp)) h << h.script('''YAHOO.util.Event.onDOMReady(function() { var region = YAHOO.util.Dom.getRegion('%(input_id)s'); YAHOO.util.Dom.setXY('%(calendar_id)s', [region.left, region.bottom + 3]); });''' % dict(input_id=input_id, calendar_id=calendar_id), type='text/javascript') h << h.div(class_='clear') return h.root
def test_get_month_names(self): self.assertEqual(i18n.get_month_names(), {1: u'janvier', 2: u'février', 3: u'mars', 4: u'avril', 5: u'mai', 6: u'juin', 7: u'juillet', 8: u'août', 9: u'septembre', 10: u'octobre', 11: u'novembre', 12: u'décembre'}) self.assertEqual(i18n.get_month_names(width='wide'), {1: u'janvier', 2: u'février', 3: u'mars', 4: u'avril', 5: u'mai', 6: u'juin', 7: u'juillet', 8: u'août', 9: u'septembre', 10: u'octobre', 11: u'novembre', 12: u'décembre'}) self.assertEqual(i18n.get_month_names(width='abbreviated'), {1: u'janv.', 2: u'févr.', 3: u'mars', 4: u'avr.', 5: u'mai', 6: u'juin', 7: u'juil.', 8: u'août', 9: u'sept.', 10: u'oct.', 11: u'nov.', 12: u'déc.'}) self.assertEqual(i18n.get_month_names(width='narrow'), {1: u'J', 2: u'F', 3: u'M', 4: u'A', 5: u'M', 6: u'J', 7: u'J', 8: u'A', 9: u'S', 10: u'O', 11: u'N', 12: u'D'})
def render_async(self, h, comp, *args): with h.div(class_='calendar-input'): input_id = h.generate_id('input') calendar_id = h.generate_id('calendar') if self.is_hidden: style = 'display: none;' else: style = 'display: block;' with h.div(class_='calendar', id_=calendar_id, style=style): with h.div(class_='calendar-header'): with h.a(title=_(u'Previous')).action(self.previous_month): h << h.i(class_='icon-arrow-left', title=_(u'Previous')) with h.span(class_='current'): with h.select(onchange=ajax.Update( action=self.change_month)): for n, month in i18n.get_month_names().iteritems(): month = month.capitalize() h << h.option(month, value=n).selected( self.current.month) h << u' ' with h.select(onchange=ajax.Update( action=self.change_year)): for year in xrange(self.current.year - YEARS_AROUND, self.current.year + YEARS_AROUND): h << h.option(year, value=year).selected( self.current.year) with h.a(title=_(u'Next')).action(self.next_month): h << h.i(class_='icon-arrow-right', title=_(u'Next')) with h.div(class_='calendar-content'): if isinstance(self.date, date): if self.current.year == self.date.year and self.current.month == self.date.month: active = self.date.day else: active = -1 else: active = -1 today = date.today() if today.month == self.current.month and today.year == self.current.year: today = today.day else: today = -1 with h.table: with h.thead: with h.tr: h << h.th(h.span(_('Wk'), title=_('Week number')), class_='week_number') days = [ day.capitalize() for day in i18n.get_day_names().itervalues() ] h << [h.th(h.span(d[:2], title=d)) for d in days] with h.tbody: for line in calendar.monthcalendar( self.current.year, self.current.month): with h.tr: week_number = date( self.current.year, self.current.month, max(1, line[0])).isocalendar()[1] h << h.td(week_number, class_='week_number') for day in line: if day == 0: h << h.td(class_='not-this-month') else: authorized = self.is_authorized_date( self.current.replace(day=day)) cls = [] if day == active: cls.append(u'active') if day == today: cls.append(u'today') if not authorized: cls.append(u'excluded') with h.td(class_=' '.join(cls)): if authorized: h << h.a(day).action( lambda day=day: self. choose_date(day, comp)) else: h << h.span(day) with h.div(class_='calendar-today'): h << h.a(h.i(class_='icon-calendar'), _(u"Today"), class_='today-link btn').action(self.set_today) if self.allow_none: h << h.a(h.i(class_='icon-remove'), _(u'None'), class_='erase btn').action( lambda: self.remove_date(comp)) h << h.script( "YAHOO.util.Event.onDOMReady(function() {" "var region = YAHOO.util.Dom.getRegion(%(input_id)s);" "YAHOO.util.Dom.setXY(%(calendar_id)s, [region.left, region.bottom + 3]);" "});" % { 'input_id': ajax.py2js(input_id), 'calendar_id': ajax.py2js(calendar_id) }) h << h.div(class_='clear') return h.root