def check_duplicates(values): duplicates = find_duplicates(values) if duplicates: duplicates_str = ', '.join(map(str, duplicates)) raise ValueError(_N(u"Duplicate value: %s", u"Duplicate values: %s", len(duplicates)) % duplicates_str) return values
def render_gallery_badge(self, h, *args): """Gallery badge for the card""" if self.assets: label = _N('file', 'files', len(self.assets)) h << h.span(h.i(class_='icon-file-text2'), ' ', len(self.assets), class_='label', data_tooltip=label) return h.root
def render_comments_badge(self, h, *args): """Comment badge for the card""" if self.comments: label = _N('comment', 'comments', len(self.comments)) h << h.span(h.i(class_='icon-bubble'), ' ', len(self.comments), class_='label', data_tooltip=label) return h.root
def render_Board_num_matches(self, h, comp, *args): if self.card_matches: if None in self.card_matches: h << h.span(_(u'No matches'), class_='nomatches') else: n = len(self.card_matches) h << (_N(u'%d match', u'%d matches', n) % n) else: h << u' ' return h.root
def comments_updated(self): if self.has_comments(): nb_comments = self.get_nb_comments() label = _N(u"Comment (%d)", u"Comments (%d)", nb_comments) % nb_comments if self.menu().has_entry('comments'): self.menu().change_label_entry('comments', label) else: menu_item = (label, 'comments', None, '', None) self.menu().add_entry_before(menu_item) self.select_tab_by_name('comments') else: if self.menu().has_entry('comments'): self.menu().remove_entry('comments') self.comment_pager().refresh_comments()
def render_Votes_badge(self, h, *args): """Badge for card in summary view User can vote by clicking on the icon """ if self.votes: label = _N('vote', 'votes', len(self.votes)) label = u'%s %s' % (len(self.votes), label) id_ = h.generate_id() link = h.a(h.i(class_='icon-heart icon-grey'), ' ', len(self.votes), class_='label', id=id_, data_tooltip=label) # Test if user can vote if security.has_permissions('vote', self.parent): link.action(self.vote) h << link h << h.script("YAHOO.util.Event.addListener('%s', 'click', YAHOO.util.Event.stopPropagation); " % id_) return h.root
def render_num_matches(self, h, comp, *args): local_h = h.SyncRenderer() input_class = '' if self.card_matches: if None in self.card_matches: local_h << local_h.span(_(u'No matches'), class_='nomatches') input_class = 'nomatches' else: n = len(self.card_matches) local_h << (_N(u'%d match', u'%d matches', n) % n) input_class = 'highlight' else: local_h << u' ' res = (local_h.root if isinstance(local_h.root, basestring) else local_h.root.write_htmlstring()) h << h.script(u'$("#show_results").html(%s);' % ajax.py2js(res).decode('utf-8')) h << h.script('document.getElementById("search").className = "%s";' % input_class) return h.root
def __init__(self, parent, idea): event_management._register_listener(parent, self) self.id = idea if is_integer(idea) else idea.id self.display_date = 'publication_date' self.comment_pager = component.Component(CommentPager(self)) self.comment_creator = component.Component( CommentCreator(self, self.id)) self.comment_creator.on_answer(lambda a: self.comments_updated()) self.wf_context = component.Component(IdeaWFContext(self.id)) event_management._register_listener(self, self.wf_context()) self.workflow_section = component.Component(WorkflowSection(self.id)) event_management._register_listener(self, self.workflow_section()) self.selected_tab = var.Var('') self.menu_items = [] if self.has_comments(): nb_comments = self.get_nb_comments() self.menu_items.append(( _N(u"Comment (%d)", u"Comments (%d)", nb_comments) % nb_comments, 'comments', None, '', None )) if self.has_challenge(): self.menu_items.append( (_(u"Challenge"), 'challenge', None, '', None)) if self.has_tags(): self.menu_items.append((_(u"Tags"), 'tags', None, '', None)) self.menu = component.Component(Menu(self.menu_items), model='tab_renderer') self.menu.on_answer(self.select_tab) self.select_default_tab() self._navigate_to_element = None self._comment_submit_id = generate_id('comment-submit') self.display_full_description = var.Var(False)
def __init__(self, parent, idea): event_management._register_listener(parent, self) self.id = idea if is_integer(idea) else idea.id self.display_date = 'publication_date' self.comment_pager = component.Component(CommentPager(self)) self.comment_creator = component.Component( CommentCreator(self, self.id)) self.comment_creator.on_answer(lambda a: self.comments_updated()) self.wf_context = component.Component(IdeaWFContext(self.id)) event_management._register_listener(self, self.wf_context()) self.workflow_section = component.Component(WorkflowSection(self.id)) event_management._register_listener(self, self.workflow_section()) self.selected_tab = var.Var('') self.menu_items = [] if self.has_comments(): nb_comments = self.get_nb_comments() self.menu_items.append( (_N(u"Comment (%d)", u"Comments (%d)", nb_comments) % nb_comments, 'comments', None, '', None)) if self.has_challenge(): self.menu_items.append( (_(u"Challenge"), 'challenge', None, '', None)) if self.has_tags(): self.menu_items.append((_(u"Tags"), 'tags', None, '', None)) self.menu = component.Component(Menu(self.menu_items), model='tab_renderer') self.menu.on_answer(self.select_tab) self.select_default_tab() self._navigate_to_element = None self._comment_submit_id = generate_id('comment-submit') self.display_full_description = var.Var(False)
def render_num_matches(self, h, comp, *args): local_h = h.SyncRenderer() input_class = '' if self.card_matches: if None in self.card_matches: local_h << local_h.span(_(u'No matches'), class_='nomatches') input_class = 'nomatches' else: n = len(self.card_matches) local_h << (_N(u'%d match', u'%d matches', n) % n) input_class = 'highlight' else: local_h << u' ' res = (local_h.root if isinstance(local_h.root, basestring) else local_h.root.write_htmlstring()) h << h.script( u'$("#show_results").html(%s);' % ajax.py2js(res).decode('utf-8')) h << h.script( 'document.getElementById("search").className = "%s";' % input_class) return h.root
def test_N_plural(self): s = i18n._N('horse', 'horses', 3) self.assertIsInstance(s, unicode) self.assertEqual(s, u'chevaux')
def render_gallery_badge(self, h, *args): """Gallery badge for the card""" if self.assets: label = _N("file", "files", len(self.assets)) h << h.span(h.i(class_="icon-file icon-grey"), " ", len(self.assets), class_="label", data_tooltip=label) return h.root
def render_gallery_badge(self, h, *args): """Gallery badge for the card""" if self.assets: label = _N('file', 'files', len(self.assets)) h << h.span(h.i(class_='icon-file icon-grey'), ' ', len(self.assets), class_='label', data_tooltip=label) return h.root
def test_N_singular(self): s = i18n._N('horse', 'horses', 1) self.assertIsInstance(s, unicode) self.assertEqual(s, u'cheval')
def test_N_plural(): s = i18n._N('horse', 'horses', 3) assert isinstance(s, type(u'')) assert s == u'chevaux'
def test_N_singular(): s = i18n._N('horse', 'horses', 1) assert isinstance(s, type(u'')) assert s == u'cheval'
def test_N_plural(): s = i18n._N('horse', 'horses', 3) assert isinstance(s, unicode) and (s == u'chevaux')
def test_N_singular(): s = i18n._N('horse', 'horses', 1) assert isinstance(s, unicode) and (s == u'cheval')
def render_comments_badge(self, h, *args): """Comment badge for the card""" if self.comments: label = _N('comment', 'comments', len(self.comments)) h << h.span(h.i(class_='icon-comment icon-grey'), ' ', len(self.comments), class_='label', data_tooltip=label) return h.root