當前位置: 首頁>>代碼示例>>Python>>正文


Python interfaces.ITitledTokenizedTerm類代碼示例

本文整理匯總了Python中zope.schema.interfaces.ITitledTokenizedTerm的典型用法代碼示例。如果您正苦於以下問題:Python ITitledTokenizedTerm類的具體用法?Python ITitledTokenizedTerm怎麽用?Python ITitledTokenizedTerm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ITitledTokenizedTerm類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: items

 def items(self):
     items = []
     if self.terms is not None:
         # update() has been called
         if ((not self.required or self.prompt)
             and not bool(self.multiple)):
             message = self.noValueMessage
             if self.prompt:
                 message = self.promptMessage
             items.append({
                 'id': self.id + '-novalue',
                 'value': self.noValueToken,
                 'content': message,
                 'selected': self.value == []
                 })
         for count, term in enumerate(self.terms):
             selected = self.isSelected(term)
             id = '%s-%i' % (self.id, count)
             content = term.token
             if ITitledTokenizedTerm.providedBy(term):
                 content = translate(
                     term.title,
                     context=self.request,
                     default=term.title)
             items.append(
                 {'id':id,
                  'value':term.token,
                  'content':content,
                  'selected':selected})
     return items
開發者ID:damilgra,項目名稱:collective.z3cform.chosen,代碼行數:30,代碼來源:widget.py

示例2: test_get_term_by_token

 def test_get_term_by_token(self):
     # we can get a term by its token
     source = RedisAutocompleteSource(
         host=self.redis_host, port=self.redis_port,
         zset_name="autocomplete-foo")
     result = source.getTermByToken(u'1')
     self.assertTrue(ITitledTokenizedTerm.providedBy(result))
開發者ID:clamor,項目名稱:psj.content,代碼行數:7,代碼來源:test_sources.py

示例3: cmp

 def cmp(self, term, query):
     # ajax search widget does a search on this vocabulary,
     # if we have titled terms, we have to compare against the title
     # otherwise use the value.
     if ITitledTokenizedTerm.providedBy(term):
         return query in term.title.lower()
     return query in term.value.lower()
開發者ID:gu-eresearch,項目名稱:gu.z3cform.rdf,代碼行數:7,代碼來源:vocabulary.py

示例4: items

    def items(self):
        # TODO: check if we should cache the return list
        if self.terms is None:  # update() not yet called
            return ()
        vocab = getUtility(
            IVocabularyFactory, "org.bccvl.site.algorithm_category_vocab")(self.context)
        items = OrderedDict((cat.value, [])
                            for cat in chain((SimpleTerm(None),), vocab))
        for count, term in enumerate(self.terms):
            alg = term.brain.getObject()
            # skip algorithm without category
            # if alg.algorithm_category is None or alg.algorithm_category not in items:
            #     continue
            itemList = items[alg.algorithm_category]
            checked = self.isChecked(term)
            id = '%s-%i' % (self.id, count)
            if ITitledTokenizedTerm.providedBy(term):
                label = translate(
                    term.title, context=self.request, default=term.title)
            else:
                label = util.toUnicode(term.value)

            catterm = SimpleTerm(None)
            if alg.algorithm_category in vocab:
                catterm = vocab.getTerm(alg.algorithm_category)
            itemList.append({'id': id, 'name': self.name + ':list', 'value': term.token,
                             'label': label, 'checked': checked,
                             'subject': term.brain.Subject,
                             'description': term.brain.Description,
                             'category': catterm,
                             'pos': len(itemList)})
        return items.values()
開發者ID:BCCVL,項目名稱:org.bccvl.site,代碼行數:32,代碼來源:widgets.py

示例5: users

    def users(self):
        context = self.context
        memtool = getToolByName(context, 'portal_membership')
        vocabulary = queryUtility(schema.interfaces.IVocabularyFactory,
                                  name='ftw.notification.base.users',
                                  context=context)
        if vocabulary:
            users = vocabulary(context)

            finalized = []
            for t in users:
                userid = t.value
                member = memtool.getMemberById(userid)
                if member is None:
                    continue

                title = t.title if ITitledTokenizedTerm.providedBy(t) else t.value
                user = dict(title=title,
                            value=t.value,
                            email=member.getProperty("email", ""),
                            selected=t.value in self.pre_select)
                finalized.append(user)

            finalized.sort(key=lambda user: user['title'].lower())
        return finalized
開發者ID:4teamwork,項目名稱:ftw.notification.base,代碼行數:25,代碼來源:views.py

示例6: test_iter

 def test_iter(self):
     # we can iterate over all elements
     source = RedisAutocompleteSource(
         host=self.redis_host, port=self.redis_port,
         zset_name="autocomplete-foo")
     elem_list = [x for x in source]
     self.assertEqual(len(elem_list), 4)
     self.assertTrue(ITitledTokenizedTerm.providedBy(elem_list[0]))
開發者ID:clamor,項目名稱:psj.content,代碼行數:8,代碼來源:test_sources.py

示例7: render_default_title

    def render_default_title(self, item, value):
        """Render the default title colum with the term's title."""

        term = self.terms.getTerm(item)

        if ITitledTokenizedTerm.providedBy(term):
            label = translate(term.title, context=self.request,
                              default=term.title)
        else:
            label = util.toUnicode(term.value)
        return label
開發者ID:lukasgraf,項目名稱:opengever.core,代碼行數:11,代碼來源:widgets.py

示例8: test_get_term_contained

 def test_get_term_contained(self):
     # we can get contained terms as ITerm
     source = RedisSource(host=self.redis_host, port=self.redis_port)
     term = source.getTerm(u'foo')
     assert ITitledTokenizedTerm.providedBy(term)
     self.assertTrue(hasattr(term, 'value'))
     self.assertEqual(term.value, u'foo')
     self.assertTrue(hasattr(term, 'token'))
     self.assertEqual(term.token, 'Zm9v')
     self.assertTrue(hasattr(term, 'title'))
     self.assertEqual(term.title, u'bar')
開發者ID:clamor,項目名稱:psj.content,代碼行數:11,代碼來源:test_sources.py

示例9: addItem

 def addItem(idx, group, term, prefix=''):
     selected = self.isSelected(term)
     if selected:
         ignored.remove(term.token)
     id = '%s-%s%i' % (self.id, prefix, idx)
     content = term.token
     if ITitledTokenizedTerm.providedBy(term):
         content = translate(
             term.title, context=self.request, default=term.title)
     optgroups[group].append(
         {'id': id, 'value': term.token, 'content': content,
          'selected': selected})
開發者ID:gu-eresearch,項目名稱:gu.z3cform.rdf,代碼行數:12,代碼來源:groupedselect.py

示例10: render_default_title

    def render_default_title(self, item, value):
        """Render the default title colum with the term's title."""
        if isinstance(item, NullObject):
            return _(u'label_none', default=u'None')

        term = self.terms.getTerm(item)

        if ITitledTokenizedTerm.providedBy(term):
            label = translate(term.title, context=self.request,
                              default=term.title)
        else:
            label = util.toUnicode(term.value)
        return label
開發者ID:4teamwork,項目名稱:opengever.core,代碼行數:13,代碼來源:widgets.py

示例11: textForValue

    def textForValue(self, term):
        """Extract a string from the `term`.

        The `term` must be a vocabulary tokenized term.

        This can be overridden to support more complex `term`
        objects. The token is returned here since it's the only thing
        known to be a string, or str()able.

        """
        if ITitledTokenizedTerm.providedBy(term):
            return self.translate(term.title)
        return term.token
開發者ID:wpjunior,項目名稱:proled,代碼行數:13,代碼來源:itemswidgets.py

示例12: items

 def items(self):
     if self.terms is None:  # update() has not been called yet
         return ()
     items = []
     if self.multiple is None:
         message = self.noValueMessage
         if self.prompt:
             message = self.promptMessage
         items.append({
             'id': self.id + '-novalue',
             'value': self.noValueToken,
             'content': message,
             'selected': self.value == []
             })
     unordered_items = {}
     optgroups = []
     for count, term in enumerate(self.terms):
         # Exctract optgroups in an ordered list, so we can use this to
         # preserve the main order of optgroups.
         if not term.optgroup in optgroups:
             optgroups.append(term.optgroup)
         selected = self.isSelected(term)
         id = '%s-%i' % (self.id, count)
         content = term.title
         if ITitledTokenizedTerm.providedBy(term):
             content = self.getContent(term)
         if not term.optgroup in unordered_items:
             unordered_items[term.optgroup] = []
         unordered_items[term.optgroup].append({
             'id': id,
             'value': term.token,
             'content': content,
             'selected': selected,
         })
     for group in optgroups:
         if not group:
             for ding in unordered_items[group]:
                 items.append({
                     'id': ding['id'],
                     'value': ding['value'],
                     'content': ding['content'],
                     'selected': ding['value'] == []
                     })
         else:
             item = {}
             item['title'] = group
             item['member'] = unordered_items[group]
             items.append(item)
     self.getSize(items)
     return items
開發者ID:fourdigits,項目名稱:z3c.formwidget.optgroup,代碼行數:50,代碼來源:widget.py

示例13: _overrideValue

    def _overrideValue(self, widget, value):
        if value:
            widget.value = ['selected']

        widget.items = []
        for count, term in enumerate(widget.terms):
            checked = widget.isChecked(term)
            id = '%s-%i' % (widget.id, count)
            label = term.token
            if ITitledTokenizedTerm.providedBy(term):
                label = translate(term.title, context=widget.request,
                                  default=term.title)
            widget.items.append({'id': id, 'name': widget.name + ':list',
                'value': term.token, 'label': label, 'checked': checked})
開發者ID:kroman0,項目名稱:products,代碼行數:14,代碼來源:controlpanel.py

示例14: displayValue

 def displayValue(self):
     value = {}
     for token in self.value:
         # Ignore no value entries. They are in the request only.
         if token == self.noValueToken:
             continue
         term = self.terms.getTermByToken(token)
         if ITitledTokenizedTerm.providedBy(term):
             content = self.getContent(term)
         else:
             value.append(term.value)
         if not term.optgroup in value:
             value[term.optgroup] = []
         value[term.optgroup].append(content)
     return value
開發者ID:fourdigits,項目名稱:z3c.formwidget.optgroup,代碼行數:15,代碼來源:widget.py

示例15: items

 def items(self):
     # TODO: check if we should cache the return list
     if self.terms is None:  # update() not yet called
         return ()
     items = []
     for count, term in enumerate(self.terms):
         checked = self.isChecked(term)
         id = '%s-%i' % (self.id, count)
         if ITitledTokenizedTerm.providedBy(term):
             label = translate(term.title, context=self.request,
                               default=term.title)
         else:
             label = util.toUnicode(term.value)
         items.append ({'id': id, 'name': self.name + ':list', 'value':term.token,
                'label':label, 'checked': checked,
                'subject': term.brain.Subject})
     return items
開發者ID:sarahrichmond,項目名稱:org.bccvl.site,代碼行數:17,代碼來源:widgets.py


注:本文中的zope.schema.interfaces.ITitledTokenizedTerm類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。