def test_format_date_datetime(): d = datetime.datetime(2007, 4, 1, 15, 30, tzinfo=pytz.timezone('America/Los_Angeles')) assert i18n.format_date(d, format='full') == 'dimanche 1 avril 2007' assert i18n.format_date(d, format='long') == '1 avril 2007' assert i18n.format_date(d, format='medium') == '1 avr. 2007' assert i18n.format_date(d) == '1 avr. 2007' assert i18n.format_date(d, format='short') == '01/04/07'
def test_format_date_date(): d = datetime.date(2007, 4, 1) assert i18n.format_date(d, format='full') == 'dimanche 1 avril 2007' assert i18n.format_date(d, format='long') == '1 avril 2007' assert i18n.format_date(d, format='medium') == '1 avr. 2007' assert i18n.format_date(d) == '1 avr. 2007' assert i18n.format_date(d, format='short') == '01/04/07'
def test_format_date_date(self): d = datetime.date(2007, 4, 1) self.assertEqual(i18n.format_date(d, format='full'), 'dimanche 1 avril 2007') self.assertEqual(i18n.format_date(d, format='long'), '1 avril 2007') self.assertEqual(i18n.format_date(d, format='medium'), '1 avr. 2007') self.assertEqual(i18n.format_date(d), '1 avr. 2007') self.assertEqual(i18n.format_date(d, format='short'), '01/04/2007')
def test_format_date_datetime(self): tz = pytz.timezone('Pacific/Pitcairn') d = tz.localize(datetime.datetime(2007, 4, 1, 15, 30)) self.assertEqual(i18n.format_date(d, format='full'), 'dimanche 1 avril 2007') self.assertEqual(i18n.format_date(d, format='long'), '1 avril 2007') self.assertEqual(i18n.format_date(d, format='medium'), '1 avr. 2007') self.assertEqual(i18n.format_date(d), '1 avr. 2007') self.assertEqual(i18n.format_date(d, format='short'), '01/04/2007')
def render_challenge_period(self, h, comp, *args): one_day = timedelta(days=1) start_date = format_date(self.challenge.starting_date, format='long') end_date = format_date(self.challenge.ending_date - one_day, format='long') # ending_date is not included with h.span(class_="period"): h << _(u'from %(start_date)s') % dict(start_date=start_date) h << " " h << _(u'to %(end_date)s') % dict(end_date=end_date) return h.root
def test_format_date_date(): i18n.set_locale(i18n.Locale('fr', 'FR')) d = datetime.date(2007, 4, 1) assert i18n.format_date(d, format='full') == 'dimanche 1 avril 2007' assert i18n.format_date(d, format='long') == '1 avril 2007' assert i18n.format_date(d, format='medium') == '1 avr. 2007' assert i18n.format_date(d) == '1 avr. 2007' assert i18n.format_date(d, format='short') == '01/04/2007'
def render_challenges_admin_menu(self, h, comp, *args): ChallengeStatusMappings = { # labels and CSS class for each status ChallengeStatus.NotStarted: (_(u'Not started'), 'status-not-started'), ChallengeStatus.InProgress: (_(u'In progress'), 'status-in-progress'), ChallengeStatus.Finished: (_(u'Finished'), 'status-finished') } h << render_title(h, _(u'Challenges management')) ref_date = datetime.now() with h.table(class_='datatable'): with h.thead: with h.tr: h << h.th(_(u'Challenge name')) h << h.th(_(u'Status')) h << h.th(_(u'Actions'), class_='actions') with h.tbody: for challenge in self.challenges: with h.tr: with h.td: h << h.a( challenge.title, title=_(u'Edit the challenge') ).action(lambda id=challenge.id: self.content.call(ChallengeEditor(challenge=id, mobile_access=self.mobile_access))) with h.td: # status status = challenge.status(ref_date) label, css_class = ChallengeStatusMappings[status] # dates one_day = timedelta(days=1) start_date = format_date(challenge.starting_date) end_date = format_date(challenge.ending_date - one_day) title = _(u'From %(start_date)s to %(end_date)s') % dict(start_date=start_date, end_date=end_date) h << h.span(label, title=title, class_=css_class) with h.td(class_='actions'): if challenge.is_deletable: title = _(u'Confirm delete?') message = _(u'The challenge will be deleted. Are you sure?') js = 'return yuiConfirm(this.href, "%s", "%s", "%s", "%s")' % (title, message, _(u'Delete'), _(u'Cancel')) h << h.a(_(u'Delete the challenge'), title=_(u'Delete the challenge'), class_='delete-challenge', onclick=js).action(lambda id=challenge.id: self.delete_challenge(id)) with h.div(class_='buttons'): h << h.a(_(u'Add a challenge'), class_='confirm-button').action(lambda: self.content.call(ChallengeEditor(mobile_access=self.mobile_access))) return h.root
def test_format_date(): d = datetime.date(2007, 4, 1) set_locale(Locale('en', 'US')) assert i18n.format_date(d) == 'Apr 1, 2007' set_locale(Locale('de', 'DE')) assert i18n.format_date(d, format='full') == 'Sonntag, 1. April 2007' set_locale(Locale('en')) assert i18n.format_date(d, "EEE, MMM d, ''yy") == "Sun, Apr 1, '07"
def test_format_date_datetime(): i18n.set_locale(i18n.Locale('fr', 'FR')) tz = pytz.timezone('Pacific/Pitcairn') d = tz.localize(datetime.datetime(2007, 4, 1, 15, 30)) assert i18n.format_date(d, format='full') == 'dimanche 1 avril 2007' assert i18n.format_date(d, format='long') == '1 avril 2007' assert i18n.format_date(d, format='medium') == '1 avr. 2007' assert i18n.format_date(d) == '1 avr. 2007' assert i18n.format_date(d, format='short') == '01/04/2007'
def get_2weeks_chart(self, width, height): start_date = datetime.today().date() - timedelta(days=14) ideas = {} for item in self.get_ideas_count_day_by_day(start_date): ideas[item.formatted_date] = item.count connections = {} for item in self.get_connection_count_day_by_day(start_date): connections[item.formatted_date] = item.count labels = [ format_date(start_date + timedelta(days=days), format="short") for days in range(0, 14) ] data = [(ideas.get(item, 0), connections.get(item, 0)) for item in labels] legend_labels = [_(u'Ideas count'), _(u'Connections count')] chart = DoubleHorizontalLineChart(labels, zip(*data), width=width, height=height, legend=True, legendlabels=legend_labels) return chart.get_png()
def get_2weeks_chart(self, width, height): start_date = datetime.today().date() - timedelta(days=14) ideas = {} for item in self.get_ideas_count_day_by_day(start_date): ideas[item.formatted_date] = item.count connections = {} for item in self.get_connection_count_day_by_day(start_date): connections[item.formatted_date] = item.count labels = [ format_date(start_date + timedelta(days=days), format="short") for days in range(0, 14)] data = [(ideas.get(item, 0), connections.get(item, 0)) for item in labels] legend_labels = [_(u'Ideas count'), _(u'Connections count')] chart = DoubleHorizontalLineChart(labels, zip(*data), width=width, height=height, legend=True, legendlabels=legend_labels) return chart.get_png()
def render_polls_admin_form(self, h, comp, *args): with h.h1(class_="tab active big"): h << h.span(h.a(_(u'Polls management'))) with h.table(class_='datatable'): with h.thead: with h.tr: h << h.th(_(u'Title')) h << h.th(_(u'Question')) h << h.th(_(u'End date (included)')) h << h.th(_(u'Enabled')) h << h.th(_(u'Actions'), class_='actions') with h.tbody: for poll in self.polls: with h.tr: with h.td: h << h.a(poll.title, title=_(u'Edit the poll')).action( lambda id=poll.id: self.content.call(PollEditor(id) )) with h.td: h << h.a(poll.question, title=_(u'Edit the poll') ).action(lambda id=poll.id: self.content.call( PollEditor(id))) with h.td: one_day = timedelta(days=1) end_date = format_date(poll.end_date - one_day) h << end_date with h.td: if poll.enabled: h << h.a( _(u'Yes'), title=_(u'Disable'), class_='yes').action(lambda id=poll.id: self. set_enabled(id, False)) else: h << h.a( _(u'No'), title=_(u'Enable'), class_='no').action(lambda id=poll.id: self. set_enabled(id, True)) with h.td(class_='actions'): title = _(u'Confirm delete?') message = _(u'The poll will be deleted. Are you sure?') js = 'return yuiConfirm(this.href, "%s", "%s", "%s", "%s")' % ( title, message, _(u'Delete'), _(u'Cancel')) h << h.a(_(u'Delete the poll'), title=_(u'Delete the poll'), class_='delete-poll', onclick=js).action( lambda id=poll.id: self.delete_poll(id)) with h.div(class_='buttons'): h << h.a(_(u'Add a poll'), class_='confirm-button').action( lambda: self.content.call(PollEditor())) return h.root
def export(self): sheet_name = fname = unicodedata.normalize('NFKD', self.data.title).encode( 'ascii', 'ignore') fname = re.sub('\W+', '_', fname.lower()) sheet_name = re.sub('\W+', ' ', sheet_name) f = StringIO() wb = xlwt.Workbook() ws = wb.add_sheet(sheet_name[:31]) sty = '' header_sty = xlwt.easyxf( sty + 'font: bold on; align: wrap on, vert centre, horiz center;') sty = xlwt.easyxf(sty) titles = [_(u'Column'), _(u'Title'), _(u'Description'), _(u'Due date')] if self.weighting_cards: titles.append(_(u'Weight')) titles.append(_(u'Comments')) for col, title in enumerate(titles): ws.write(0, col, title, style=header_sty) row = 1 max_len = len(titles) for col in self.columns: col = col().data for card in col.cards: colnumber = 0 ws.write(row, colnumber, _('Archived cards') if col.archive else col.title, sty) colnumber += 1 ws.write(row, colnumber, card.title, sty) colnumber += 1 ws.write(row, colnumber, card.description, sty) colnumber += 1 ws.write(row, colnumber, format_date(card.due_date) if card.due_date else u'', sty) colnumber += 1 if self.weighting_cards: ws.write(row, colnumber, card.weight, sty) colnumber += 1 for colno, comment in enumerate(card.comments, colnumber): ws.write(row, colno, comment.comment, sty) max_len = max(max_len, 4 + colno) row += 1 for col in xrange(len(titles)): ws.col(col).width = 0x3000 ws.set_panes_frozen(True) ws.set_horz_split_pos(1) wb.save(f) f.seek(0) e = exc.HTTPOk() e.content_type = 'application/vnd.ms-excel' e.content_disposition = u'attachment;filename=%s.xls' % fname e.body = f.getvalue() raise e
def render_polls_admin_form(self, h, comp, *args): with h.h1(class_="tab active big"): h << h.span(h.a(_(u'Polls management'))) with h.table(class_='datatable'): with h.thead: with h.tr: h << h.th(_(u'Title')) h << h.th(_(u'Question')) h << h.th(_(u'End date (included)')) h << h.th(_(u'Enabled')) h << h.th(_(u'Actions'), class_='actions') with h.tbody: for poll in self.polls: with h.tr: with h.td: h << h.a( poll.title, title=_(u'Edit the poll') ).action(lambda id=poll.id: self.content.call(PollEditor(id))) with h.td: h << h.a( poll.question, title=_(u'Edit the poll') ).action(lambda id=poll.id: self.content.call(PollEditor(id))) with h.td: one_day = timedelta(days=1) end_date = format_date(poll.end_date - one_day) h << end_date with h.td: if poll.enabled: h << h.a(_(u'Yes'), title=_(u'Disable'), class_='yes').action(lambda id=poll.id: self.set_enabled(id, False)) else: h << h.a(_(u'No'), title=_(u'Enable'), class_='no').action(lambda id=poll.id: self.set_enabled(id, True)) with h.td(class_='actions'): title = _(u'Confirm delete?') message = _(u'The poll will be deleted. Are you sure?') js = 'return yuiConfirm(this.href, "%s", "%s", "%s", "%s")' % (title, message, _(u'Delete'), _(u'Cancel')) h << h.a(_(u'Delete the poll'), title=_(u'Delete the poll'), class_='delete-poll', onclick=js).action(lambda id=poll.id: self.delete_poll(id)) with h.div(class_='buttons'): h << h.a(_(u'Add a poll'), class_='confirm-button').action(lambda: self.content.call(PollEditor())) return h.root
def render_idea_wf_context_last_comment(self, h, comp, *args): comments = self.comments if len(comments) > 0: with h.div(class_="warning"): date = format_date(comments[-1].data.submission_date) h << h.h1(_(u'This idea has been refused on %s') % date) h << h.h2(_(u"The expert opinion:")) h << h.div(comments[-1].content) return h.root
def render_DueDate_badge(self, h, *args): """Gallery badge for the card""" if self.due_date: with h.span(class_='badge'): h << h.span(h.i(class_='icon-alarm'), ' ', self.get_days_count(), class_='label due-date ' + self.get_class(), title=format_date(self.due_date, 'full')) return h.root
def export(self): sheet_name = fname = unicodedata.normalize('NFKD', self.data.title).encode('ascii', 'ignore') fname = re.sub('\W+', '_', fname.lower()) sheet_name = re.sub('\W+', ' ', sheet_name) f = StringIO() wb = xlwt.Workbook() ws = wb.add_sheet(sheet_name[:31]) sty = '' header_sty = xlwt.easyxf(sty + 'font: bold on; align: wrap on, vert centre, horiz center;') sty = xlwt.easyxf(sty) titles = [_(u'Column'), _(u'Title'), _(u'Description'), _(u'Due date')] if self.weighting_cards: titles.append(_(u'Weight')) titles.append(_(u'Comments')) for col, title in enumerate(titles): ws.write(0, col, title, style=header_sty) row = 1 max_len = len(titles) for col in self.columns: col = col().data for card in col.cards: colnumber = 0 ws.write(row, colnumber, _('Archived cards') if col.archive else col.title, sty) colnumber += 1 ws.write(row, colnumber, card.title, sty) colnumber += 1 ws.write(row, colnumber, card.description, sty) colnumber += 1 ws.write(row, colnumber, format_date(card.due_date) if card.due_date else u'', sty) colnumber += 1 if self.weighting_cards: ws.write(row, colnumber, card.weight, sty) colnumber += 1 for colno, comment in enumerate(card.comments, colnumber): ws.write(row, colno, comment.comment, sty) max_len = max(max_len, 4 + colno) row += 1 for col in xrange(len(titles)): ws.col(col).width = 0x3000 ws.set_panes_frozen(True) ws.set_horz_split_pos(1) wb.save(f) f.seek(0) e = exc.HTTPOk() e.content_type = 'application/vnd.ms-excel' e.content_disposition = u'attachment;filename=%s.xls' % fname e.body = f.getvalue() raise e
def _get_substitutions(to, comment=None, idea=None, fi=None, previous_di=None, comment_author=None, **kw): # initialize useful values for substitutions base_url = get_url_service().base_url shop_url = get_url_service().expand_url(['shop'], relative=False) idea_url = get_url_service().expand_url(['idea', idea.id], relative=False) if idea else u'' fi = fi or (idea.wf_context.assignated_fi if idea else None) di = idea.wf_context.assignated_di if idea else None mailer = mail.get_mailer() # creates the substitutions substitutions = { u'RECIPIENT_LOGIN': to.uid if to else u'', u'RECIPIENT_FIRSTNAME': to.firstname if to else u'', u'RECIPIENT_LASTNAME': to.lastname if to else u'', u'RECIPIENT_EMAIL': to.email or u'' if to else u'', u'FI_FIRSTNAME': fi.firstname if fi else u'', u'FI_LASTNAME': fi.lastname if fi else u'', u'FI_EMAIL': fi.email if fi and fi.email else u'', u'DI_FIRSTNAME': di.firstname if di else u'', u'DI_LASTNAME': di.lastname if di else u'', u'DI_EMAIL': di.email if di and di.email else u'', u'IDEA_ID': str(idea.id) if idea else u'', u'IDEA_TITLE': text_to_html(idea.title) if idea else u'', u'IDEA_LINK_HERE': render_link(_(u'here'), idea_url), u'SUBMISSION_DATE': format_date(datetime.today(), format='medium'), u'COMMENT': text_to_html(comment or u''), u'COMMENT_AUTHOR_FIRSTNAME': comment_author.firstname if comment_author else '', u'COMMENT_AUTHOR_LASTNAME': comment_author.lastname if comment_author else '', u'EUREKA_LINK': render_link(_(u'Eurêka'), base_url), u'EUREKA_URL_LINK': render_link(base_url, base_url), u'SHOP_LINK': render_link(_(u'shop'), shop_url), u'PREVIOUS_DI_EMAIL': (previous_di.email if (previous_di and previous_di.email) else u''), u'PREVIOUS_DI_FIRSTNAME': (previous_di.firstname if (previous_di and previous_di.firstname) else u''), u'PREVIOUS_DI_LASTNAME': (previous_di.lastname if (previous_di and previous_di.lastname) else u''), } substitutions.update(mailer.get_substitutions()) substitutions.update({k.upper(): v for k, v in kw.iteritems()}) return substitutions
def render_DueDate_button(self, h, comp, *args): if security.has_permissions('due_date', self.card): id_ = h.generate_id() if self.due_date: classes = ['btn', 'btn-due-date', self.get_class()] with h.a(class_=u' '.join(classes), id_=id_).action(self.calendar().toggle): h << h.i(class_='icon-alarm duedate-icon') h << format_date(self.due_date, 'short') else: with h.a(class_='btn', id_=id_).action(self.calendar().toggle): h << h.i(class_='icon-alarm') h << _('Due date') h << self.calendar.on_answer(self.set_value) return h.root
def format_time_elapsed(date, format='medium'): now = datetime.now() elapsed = now - date if elapsed.days > 0: return _("On") + " " + format_date(date, format) else: hours = elapsed.seconds / 3600 if hours > 0: return _("%d hours ago") % hours minutes = elapsed.seconds / 60 if minutes > 0: return _("%d minutes ago") % minutes return _("%d seconds ago") % elapsed.seconds
def test_format_date_date_with_format(): i18n.set_locale(i18n.Locale('fr', 'FR')) d = datetime.date(2007, 4, 1) assert i18n.format_date(d, 'EEE, MMM d, yy') == 'dim., avr. 1, 07'
def render_DueDate_badge(self, h, *args): """Gallery badge for the card""" if self.value: h << h.span(h.i(class_='icon-time icon-grey'), ' ', self.get_days_count(), class_='label due-date ' + self.get_class(), data_tooltip=format_date(self.value, 'full')) return h.root
def test_format_date_date_with_format(): d = datetime.date(2007, 4, 1) assert i18n.format_date(d, "EEE, MMM d, yy") == 'dim., avr. 1, 07'
def render_administration_menu(self, h, comp, *args): with h.div(class_="admin-menu rounded"): h << h.h2(_(u'Statistics')) with h.ul: with h.li: with h.a(class_="dashboard").action(self.show_dashboard): h << _(u'Dashboard') with h.li: with h.a(class_="liked-comments").action( self.show_most_liked_comments): h << _(u'Most Liked Comments') with h.span(class_='download'): h << _("Download") board_export_url, board_export_date = None, None if self.configuration['administration']['board_export']: board_export_url, board_export_date = self.last_board_export() if board_export_url: with h.li: with h.a(class_='last-export', href=board_export_url): h << _(u'Last Export: %s') % format_date( board_export_date) with h.span(class_='download'): h << _("Download") stats_url = self.configuration['administration']['stats_url'] if stats_url: with h.li: with h.a(class_='desktop-visits', href='#', onclick=('window.open("%s"); ' 'return false') % stats_url): h << _("Visits on the Desktop Platform") h << h.h2(_(u'Directories')) with h.ul: with h.li: with h.a(class_="user-admin").action(self.show_users): h << _(u'Users') with h.li: with h.a(class_="fi-admin").action(self.show_fis): h << _(u'Facilitators') with h.li: with h.a(class_="di-admin").action(self.show_dis): h << _(u'Developers') h << h.h2(_(u'Communication / Site activities')) with h.ul: with h.li: with h.a(class_='points-admin').action(self.show_points): h << _(u'Points') with h.li: with h.a(class_='challenges-admin').action( self.show_challenges): h << _(u'Challenges') with h.li: with h.a(class_='articles-admin').action(self.show_articles): h << _(u'Articles') with h.li: with h.a(class_='polls-admin').action(self.show_polls): h << _(u'Polls') return h.root
def render_suggestion(self, h, comp, *args): masked_class = '' if self.data.visible else ' masked' with h.li(class_='collapse suggestion' + masked_class): content = self.data.content shortcontent = limit_string(content, 85)[1:] if len(content) > 85 else content # expand/collapse button if len(shortcontent) != len(content): h << h.a(class_="toggle on", onclick='toggleCollapseExpand(this);', title=_(u"Show the whole suggestion")) h << h.a(class_="toggle off", onclick='toggleCollapseExpand(this);', title=_(u"Hide the whole suggestion")) # icon icon_info_by_state = { ImprovementState.TREATED: (_(u'Suggestion processed and deployed'), 'flag_green.png'), ImprovementState.RUNNING: (_(u'Suggestion in progress'), 'flag_yellow.png'), ImprovementState.REJECTED: (_(u'Suggestion rejected'), 'flag_red.png'), } icon_info = icon_info_by_state.get(self.data.state, None) if icon_info: title, icon_name = icon_info icon_url = "%sstyle/desktop/icons/%s" % (h.head.static_url, icon_name) h << h.img(title=title, alt=title, src=icon_url, class_="flag") # short and full content blocks with h.p(class_='meta'): h << _(u"from").capitalize() << " " h << h.span(self.data.user.fullname, class_='author') h << " " << _(u'at') << ' ' h << h.span(format_date(self.data.submission_date, format='short'), lass_='submission date') h << " - " h << _(self.data.domain.label) h << h.p(shortcontent, class_='short content') h << h.p(content, class_='long content') # actions if security.has_permissions('edit', self): with h.div(class_='actions'): # visibility toggle visible = self.data.visible label = _(u'Hide') if visible else _(u'Show') title = _(u'Hide the suggestion') if visible else _(u'Show the suggestion') h << h.a(label, title=title).action(self.toggle_visibility) # change state actions title = _(u'Mark as rejected') rejected_action = h.a(title, title=title).action(lambda: self.change_state(ImprovementState.REJECTED)) title = _(u'Mark as in progress') running_action = h.a(title, title=title).action(lambda: self.change_state(ImprovementState.RUNNING)) title = _(u'Mark as processed') treated_action = h.a(title, title=title).action(lambda: self.change_state(ImprovementState.TREATED)) actions_by_state = { ImprovementState.NEW: (rejected_action, treated_action, running_action), ImprovementState.RUNNING: (rejected_action, treated_action) } actions = actions_by_state.get(self.data.state, None) if actions: for action in actions: h << h.a(u' | ') h << action return h.root
def render_suggestion(self, h, comp, *args): masked_class = '' if self.data.visible else ' masked' with h.li(class_='collapse suggestion' + masked_class): content = self.data.content shortcontent = limit_string(content, 85)[1:] if len(content) > 85 else content # expand/collapse button if len(shortcontent) != len(content): h << h.a(class_="toggle on", onclick='toggleCollapseExpand(this);', title=_(u"Show the whole suggestion")) h << h.a(class_="toggle off", onclick='toggleCollapseExpand(this);', title=_(u"Hide the whole suggestion")) # icon icon_info_by_state = { ImprovementState.TREATED: (_(u'Suggestion processed and deployed'), 'flag_green.png'), ImprovementState.RUNNING: (_(u'Suggestion in progress'), 'flag_yellow.png'), ImprovementState.REJECTED: (_(u'Suggestion rejected'), 'flag_red.png'), } icon_info = icon_info_by_state.get(self.data.state, None) if icon_info: title, icon_name = icon_info icon_url = "%sstyle/desktop/icons/%s" % (h.head.static_url, icon_name) h << h.img(title=title, alt=title, src=icon_url, class_="flag") # short and full content blocks with h.p(class_='meta'): h << _(u"from").capitalize() << " " h << h.span(self.data.user.fullname, class_='author') h << " " << _(u'at') << ' ' h << h.span(format_date(self.data.submission_date, format='short'), lass_='submission date') h << " - " h << _(self.data.domain.label) h << h.p(shortcontent, class_='short content') h << h.p(content, class_='long content') # actions if security.has_permissions('edit', self): with h.div(class_='actions'): # visibility toggle visible = self.data.visible label = _(u'Hide') if visible else _(u'Show') title = _(u'Hide the suggestion') if visible else _( u'Show the suggestion') h << h.a(label, title=title).action(self.toggle_visibility) # change state actions title = _(u'Mark as rejected') rejected_action = h.a(title, title=title).action( lambda: self.change_state(ImprovementState.REJECTED)) title = _(u'Mark as in progress') running_action = h.a(title, title=title).action( lambda: self.change_state(ImprovementState.RUNNING)) title = _(u'Mark as processed') treated_action = h.a(title, title=title).action( lambda: self.change_state(ImprovementState.TREATED)) actions_by_state = { ImprovementState.NEW: (rejected_action, treated_action, running_action), ImprovementState.RUNNING: (rejected_action, treated_action) } actions = actions_by_state.get(self.data.state, None) if actions: for action in actions: h << h.a(u' | ') h << action return h.root
def write_extension_data_DueDate(self, sheet, row, col, style): value = self.get_value() sheet.write(row, col, format_date(value) if value else u'', style)
def str_date(self): if self.date is None: return u'' return i18n.format_date(self.date, 'short')
def render_administration_menu(self, h, comp, *args): with h.div(class_="admin-menu rounded"): h << h.h2(_(u'Statistics')) with h.ul: with h.li: with h.a(class_="dashboard").action(self.show_dashboard): h << _(u'Dashboard') with h.li: with h.a(class_="liked-comments").action(self.show_most_liked_comments): h << _(u'Most Liked Comments') with h.span(class_='download'): h << _("Download") board_export_url, board_export_date = None, None if self.configuration['administration']['board_export']: board_export_url, board_export_date = self.last_board_export() if board_export_url: with h.li: with h.a(class_='last-export', href=board_export_url): h << _(u'Last Export: %s') % format_date(board_export_date) with h.span(class_='download'): h << _("Download") stats_url = self.configuration['administration']['stats_url'] if stats_url: with h.li: with h.a( class_='desktop-visits', href='#', onclick=('window.open("%s"); ' 'return false') % stats_url): h << _("Visits on the Desktop Platform") h << h.h2(_(u'Directories')) with h.ul: with h.li: with h.a(class_="user-admin").action(self.show_users): h << _(u'Users') with h.li: with h.a(class_="fi-admin").action(self.show_fis): h << _(u'Facilitators') with h.li: with h.a(class_="di-admin").action(self.show_dis): h << _(u'Developers') h << h.h2(_(u'Communication / Site activities')) with h.ul: with h.li: with h.a(class_='points-admin').action(self.show_points): h << _(u'Points') with h.li: with h.a(class_='challenges-admin').action(self.show_challenges): h << _(u'Challenges') with h.li: with h.a(class_='articles-admin').action(self.show_articles): h << _(u'Articles') with h.li: with h.a(class_='polls-admin').action(self.show_polls): h << _(u'Polls') return h.root
def test_format_date_date_with_format(self): d = datetime.date(2007, 4, 1) self.assertEqual(i18n.format_date(d, 'EEE, MMM d, yy'), 'dim., avr. 1, 07')
def render_challenges_admin_menu(self, h, comp, *args): ChallengeStatusMappings = { # labels and CSS class for each status ChallengeStatus.NotStarted: (_(u'Not started'), 'status-not-started'), ChallengeStatus.InProgress: (_(u'In progress'), 'status-in-progress'), ChallengeStatus.Finished: (_(u'Finished'), 'status-finished') } h << render_title(h, _(u'Challenges management')) ref_date = datetime.now() with h.table(class_='datatable'): with h.thead: with h.tr: h << h.th(_(u'Challenge name')) h << h.th(_(u'Status')) h << h.th(_(u'Actions'), class_='actions') with h.tbody: for challenge in self.challenges: with h.tr: with h.td: h << h.a( challenge.title, title=_(u'Edit the challenge') ).action(lambda id=challenge.id: self.content.call( ChallengeEditor(challenge=id, mobile_access=self.mobile_access))) with h.td: # status status = challenge.status(ref_date) label, css_class = ChallengeStatusMappings[status] # dates one_day = timedelta(days=1) start_date = format_date(challenge.starting_date) end_date = format_date(challenge.ending_date - one_day) title = _( u'From %(start_date)s to %(end_date)s') % dict( start_date=start_date, end_date=end_date) h << h.span(label, title=title, class_=css_class) with h.td(class_='actions'): if challenge.is_deletable: title = _(u'Confirm delete?') message = _( u'The challenge will be deleted. Are you sure?' ) js = 'return yuiConfirm(this.href, "%s", "%s", "%s", "%s")' % ( title, message, _(u'Delete'), _(u'Cancel')) h << h.a( _(u'Delete the challenge'), title=_(u'Delete the challenge'), class_='delete-challenge', onclick=js).action(lambda id=challenge.id: self .delete_challenge(id)) with h.div(class_='buttons'): h << h.a(_(u'Add a challenge'), class_='confirm-button').action(lambda: self.content.call( ChallengeEditor(mobile_access=self.mobile_access))) return h.root
def render_DueDate_badge(self, h, *args): """Gallery badge for the card""" if self.value: h << h.span(h.i(class_='icon-alarm'), ' ', self.get_days_count(), class_='label due-date ' + self.get_class(), data_tooltip=format_date(self.value, 'full')) return h.root