示例#1
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     trusted = removeSecurityProxy(context)
     ministry_id = getattr(trusted, self.value_field, None)
     for ob in results:
         obj = translate_obj(ob)
         terms.append(
             vocabulary.SimpleTerm(
                 value=getattr(obj, 'group_id'),
                 token=getattr(obj, 'group_id'),
                 title="%s - %s" %
                 (getattr(obj, 'short_name'), getattr(obj, 'full_name'))))
     if ministry_id:
         if query.filter(domain.Group.group_id == ministry_id).count() == 0:
             session = Session()
             ob = session.query(domain.Group).get(ministry_id)
             obj = translate_obj(ob)
             terms.append(
                 vocabulary.SimpleTerm(
                     value=getattr(obj, 'group_id'),
                     token=getattr(obj, 'group_id'),
                     title="%s - %s" % (getattr(
                         obj, 'short_name'), getattr(obj, 'full_name'))))
     return vocabulary.SimpleVocabulary(terms)
示例#2
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     trusted = removeSecurityProxy(context)
     type_id = getattr(trusted, "attached_file_type_id", None)
     terms = []
     if type_id:
         session = Session()
         attached_file_type = session.query(
             domain.AttachedFileType).get(type_id)
         terms.append(
             vocabulary.SimpleTerm(
                 value=getattr(attached_file_type, "attached_file_type_id"),
                 token=getattr(attached_file_type, "attached_file_type_id"),
                 title=getattr(attached_file_type,
                               "attached_file_type_name")))
         return vocabulary.SimpleVocabulary(terms)
     else:
         for ob in results:
             if ob.attached_file_type_name not in ["system"]:
                 terms.append(
                     vocabulary.SimpleTerm(
                         value=getattr(ob, "attached_file_type_id"),
                         token=getattr(ob, "attached_file_type_id"),
                         title=getattr(ob, "attached_file_type_name"),
                     ))
         return vocabulary.SimpleVocabulary(terms)
示例#3
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         terms.append(
             vocabulary.SimpleTerm(
                 value=getattr(ob, 'user_id'),
                 token=getattr(ob, 'user_id'),
                 title="%s %s" %
                 (getattr(ob, 'first_name'), getattr(ob, 'last_name'))))
     user_id = getattr(context, self.value_field, None)
     if user_id:
         if query.filter(
                 domain.GroupMembership.user_id == user_id).count() == 0:
             # The user is not a member of this group.
             # This should not happen in real life
             # but if we do not add it her the view form will
             # throw an exception
             session = Session()
             ob = session.query(domain.User).get(user_id)
             terms.append(
                 vocabulary.SimpleTerm(
                     value=getattr(ob, 'user_id'),
                     token=getattr(ob, 'user_id'),
                     title="(%s %s)" %
                     (getattr(ob, 'first_name'), getattr(ob, 'last_name'))))
     return vocabulary.SimpleVocabulary(terms)
示例#4
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         terms.append(
             vocabulary.SimpleTerm(
                 value = getattr(ob, 'user_id'), 
                 token = getattr(ob, 'user_id'),
                 title = "%s %s" % (getattr(ob, 'first_name') ,
                         getattr(ob, 'last_name'))
                ))
     user_id = getattr(context, self.value_field, None) 
     if user_id:
         if len(query.filter(schema.users.c.user_id == user_id).all()) == 0:
             session = Session()
             ob = session.query(domain.User).get(user_id)
             terms.append(
             vocabulary.SimpleTerm(
                 value = getattr(ob, 'user_id'), 
                 token = getattr(ob, 'user_id'),
                 title = "(%s %s)" % (getattr(ob, 'first_name') ,
                         getattr(ob, 'last_name'))
                ))
     return vocabulary.SimpleVocabulary(terms)
示例#5
0
 def test_simple_term(self):
     t = vocabulary.SimpleTerm(1)
     verifyObject(interfaces.ITokenizedTerm, t)
     self.assertEqual(t.value, 1)
     self.assertEqual(t.token, "1")
     t = vocabulary.SimpleTerm(1, "One")
     verifyObject(interfaces.ITokenizedTerm, t)
     self.assertEqual(t.value, 1)
     self.assertEqual(t.token, "One")
示例#6
0
 def test_simple_term_title(self):
     t = vocabulary.SimpleTerm(1)
     verifyObject(interfaces.ITokenizedTerm, t)
     self.failUnlessRaises(DoesNotImplement, verifyObject,
         interfaces.ITitledTokenizedTerm, t)
     self.failUnless(t.title is None)
     t = vocabulary.SimpleTerm(1, title="Title")
     verifyObject(interfaces.ITokenizedTerm, t)
     verifyObject(interfaces.ITitledTokenizedTerm, t)
     self.failUnlessEqual(t.title, "Title")
示例#7
0
    def __call__(self, context):
        today = datetime.date.today()
        weekday = today.weekday()
        day = today.day

        return vocabulary.SimpleVocabulary((
            vocabulary.SimpleTerm(
                nth_day_of_month(day), "day_%d_of_every_month" % day,
                _(u"Day $number of every month", mapping={'number': day})),
            vocabulary.SimpleTerm(
                first_nth_weekday_of_month(weekday),
                "first_%s_of_every_month" % today.strftime("%a"),
                _(u"First $day of every month",
                  mapping={'day': translate(today.strftime("%A"))})),
        ))
示例#8
0
 def _makeMissingTerm(self, value):
     """Return a term that should be displayed for the missing token"""
     uvalue = util.toUnicode(value)
     return vocabulary.SimpleTerm(value,
                                  self._makeToken(value),
                                  title=_(u'Missing: ${value}',
                                          mapping=dict(value=uvalue)))
示例#9
0
def ActiveUsers(context, role=None):
    session = Session()
    terms = []
    transcription_office = session.query(
        domain.Office).filter(domain.Office.office_type == 'V').all()
    if len(transcription_office) == 0:
        return vocabulary.SimpleVocabulary(terms)
    if role == None:
        return vocabulary.SimpleVocabulary(terms)
    query = session.query(domain.GroupMembership).filter(
        sql.and_(
            domain.GroupMembership.membership_type == 'officemember',
            domain.GroupMembership.active_p == True,
            domain.GroupMembership.group_id ==
            transcription_office[0].office_id))
    results = query.all()
    for ob in results:
        titles = [t.title_name.user_role_name for t in ob.member_titles]
        if role in titles:
            obj = ob.user
            terms.append(
                vocabulary.SimpleTerm(
                    value=getattr(obj, 'user_id'),
                    token=getattr(obj, 'user_id'),
                    title=getattr(obj, 'first_name') +
                    getattr(obj, 'last_name'),
                ))
    return vocabulary.SimpleVocabulary(terms)
示例#10
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     tdict = {}
     for ob in results:
         tdict[getattr(ob.user, 'user_id')] = "%s %s" % (
                 getattr(ob.user, 'first_name') ,
                 getattr(ob.user, 'last_name'))
     user_id = getattr(context, 'replaced_id', None) 
     if user_id:
         if len(query.filter(domain.GroupMembership.replaced_id == user_id).all()) == 0:
             session = Session()
             ob = session.query(domain.User).get(user_id)
             tdict[getattr(ob, 'user_id')] = "%s %s" % (
                         getattr(ob, 'first_name') ,
                         getattr(ob, 'last_name'))
     terms = []
     for t in tdict.keys():
         terms.append(
             vocabulary.SimpleTerm(
                 value = t, 
                 token = t,
                 title = tdict[t]
                ))
     return vocabulary.SimpleVocabulary(terms)
示例#11
0
    def validate(self, values):
        if values is None:
            return super(VocabularyValuesValidator, self).validate(values)

        by_value = {}
        by_token = {}
        for value in values:
            term = vocabulary.SimpleTerm(token=value.encode('unicode_escape'),
                                         value=value,
                                         title=value)
            if term.value in by_value:
                raise interface.Invalid(
                    _('field_edit_error_conflicting_values',
                      default=
                      u"The '${value1}' vocabulary value conflicts with '${value2}'.",
                      mapping={
                          'value1': value,
                          'value2': by_value[term.value].value
                      }))

            if term.token in by_token:
                raise interface.Invalid(
                    _('field_edit_error_conflicting_values',
                      default=
                      u"The '${value1}' vocabulary value conflicts with '${value2}'.",
                      mapping={
                          'value1': value,
                          'value2': by_value[term.token].value
                      }))

            by_value[term.value] = term
            by_token[term.token] = term

        return super(VocabularyValuesValidator, self).validate(values)
示例#12
0
 def updateTerms(self):
     if self.terms is None:
         self.terms = term.Terms()
         self.terms.terms = vocabulary.SimpleVocabulary(
             (vocabulary.SimpleTerm('selected', 'selected', self.label
                                    or self.field.title), ))
     return self.terms
def ContentTypes(context):
    # context is actually a preferences object, dig another level to get to the adapted context
    # which is acq wrapped.
    portal_types = getToolByName(context.context, 'portal_types')
    terms = []
    # hmmm..
    types = filter(lambda x: x.global_allow, portal_types.objectValues())

    properties = getToolByName(context.context, 'portal_properties')
    if hasattr(properties.site_properties, 'types_not_searched'):
        types_not_searched = set(properties.site_properties.types_not_searched)
    else:
        registry = component.getUtility(IRegistry)
        settings = registry.forInterface(ISearchSchema, prefix="plone")
        types_not_searched = set(settings.types_not_searched)
    for type in portal_types.objectValues():
        if type.getId() in types_not_searched:
            continue
        terms.append(
            vocabulary.SimpleTerm(unicode(type.getId()),
                                  title=unicode(type.title_or_id())))

    terms.sort(lambda x, y: cmp(x.title, y.title))

    return vocabulary.SimpleVocabulary(terms)
示例#14
0
def _pluginVocabulary(context, interface, attr_name):
    """Vocabulary that provides names of plugins of a specified interface.

    Given an interface, the options should include the unique names of all of
    the plugins that provide the specified interface for the current context--
    which is expected to be a pluggable authentication utility, hereafter
    referred to as a PAU).

    These plugins may be objects contained within the PAU ("contained
    plugins"), or may be utilities registered for the specified
    interface, found in the context of the PAU ("utility plugins").
    Contained plugins mask utility plugins of the same name.

    The vocabulary also includes the current values of the PAU even if they do
    not correspond to a contained or utility plugin.
    """
    terms = {}
    isPAU = interfaces.IPluggableAuthentication.providedBy(context)
    if isPAU:
        for k, v in context.items():
            if interface.providedBy(v):
                dc = zope.dublincore.interfaces.IDCDescriptiveProperties(
                    v, None)
                if dc is not None and dc.title:
                    title = dc.title
                else:
                    title = k
                terms[k] = vocabulary.SimpleTerm(
                    k,
                    k.encode('base64').strip(),
                    i18n.Message(CONTAINED_TITLE, mapping={'name': title}))
    utils = component.getUtilitiesFor(interface, context)
    for nm, util in utils:
        if nm not in terms:
            terms[nm] = vocabulary.SimpleTerm(
                nm,
                nm.encode('base64').strip(),
                i18n.Message(UTILITY_TITLE, mapping={'name': nm}))
    if isPAU:
        for nm in set(getattr(context, attr_name)):
            if nm not in terms:
                terms[nm] = vocabulary.SimpleTerm(
                    nm,
                    nm.encode('base64').strip(),
                    i18n.Message(MISSING_TITLE, mapping={'name': nm}))
    return vocabulary.SimpleVocabulary(
        [term for nm, term in sorted(terms.items())])
示例#15
0
 def updateTerms(self):
     # The default implementation would render "selected" as a
     # lebel for the single checkbox.  We use no label instead.
     if self.terms is None:
         self.terms = z3c.form.term.Terms()
         self.terms.terms = vocabulary.SimpleVocabulary(
             (vocabulary.SimpleTerm(True, 'selected', u''), ))
     return self.terms
示例#16
0
 def __call__(self, context=None):
     all_terms = self.vdex.getVocabularyDict(lang=get_default_language())
     terms = []
     assert self.vdex.isFlat() is True
     for (key, data) in all_terms.iteritems():
         term = vocabulary.SimpleTerm(key, key, data[0])
         terms.append(term)
     return vocabulary.SimpleVocabulary(terms)
示例#17
0
class ICurrency(interfaces.IMinMax, interfaces.IField):

    precision = zope.schema.Choice(
        title=_('Precision'),
        description=_('The precision in which the amount is kept.'),
        vocabulary=vocabulary.SimpleVocabulary([
            vocabulary.SimpleTerm(DOLLARS, str(DOLLARS), u'Dollars'),
            vocabulary.SimpleTerm(CENTS, str(CENTS), u'Cents'),
            vocabulary.SimpleTerm(SUBCENTS, str(SUBCENTS), u'Sub-Cents'),
        ]),
        default=CENTS,
        required=True)

    unit = zope.schema.TextLine(
        title=_('Unit'),
        description=_('The unit in which the currency amount is kept.'),
        default=u'$',
        required=True)
示例#18
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         terms.append(
             vocabulary.SimpleTerm(value=ob.venue_id,
                                   token=ob.venue_id,
                                   title="%s" % (ob.short_name)))
     return vocabulary.SimpleVocabulary(terms)
示例#19
0
    def _constructVocabulary(self, value):
        terms = []
        if value:
            for value in value:
                term = vocabulary.SimpleTerm(
                    token=value.encode('unicode_escape'),
                    value=value, title=value)
                terms.append(term)

        return vocabulary.SimpleVocabulary(terms)
示例#20
0
文件: term.py 项目: bendavis78/zope
 def __init__(self, context, request, form, field, widget):
     self.context = context
     self.request = request
     self.form = form
     self.field = field
     self.widget = widget
     terms = [vocabulary.SimpleTerm(*args)
              for args in [(True, 'true', self.trueLabel),
                           (False, 'false', self.falseLabel)]]
     self.terms = vocabulary.SimpleVocabulary(terms)
示例#21
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         terms.append(
             vocabulary.SimpleTerm(value=ob.venue_id,
                                   token=ob.venue_id,
                                   title="%s" %
                                   IDCDescriptiveProperties(ob).title))
     return vocabulary.SimpleVocabulary(terms)
示例#22
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         obj = translate_obj(ob)
         terms.append(
             vocabulary.SimpleTerm(
                 value=getattr(obj, 'user_role_type_id'),
                 token=getattr(obj, 'user_role_type_id'),
                 title=getattr(obj, 'user_role_name'),
             ))
     return vocabulary.SimpleVocabulary(terms)
示例#23
0
 def __call__(self, context):
     terms = []
     while not IBungeniGroup.providedBy(context):
         context = context.__parent__
         if not context:
             raise NotImplementedError(
                 "Context does not implement IBungeniGroup")
     trusted = removeSecurityProxy(context)
     role = getUtility(IRole, get_group_local_role(trusted))
     for sub_role in ISubRoleAnnotations(role).sub_roles:
         print sub_role
         terms.append(vocabulary.SimpleTerm(sub_role, sub_role, sub_role))
     return vocabulary.SimpleVocabulary(terms)
示例#24
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     title_field = self.title_field or self.token_field
     for ob in results:
         terms.append(
             vocabulary.SimpleTerm(
                 value=getattr(ob, self.value_field),
                 token=getattr(ob, self.token_field),
                 title=getattr(ob, title_field),
             ))
     return vocabulary.SimpleVocabulary(terms)
示例#25
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         obj = translate_obj(ob)
         terms.append(
             vocabulary.SimpleTerm(
                 value=obj.group_sitting_type_id,
                 token=obj.group_sitting_type,
                 title="%s (%s-%s)" %
                 (obj.group_sitting_type, obj.start_time, obj.end_time),
             ))
     return vocabulary.SimpleVocabulary(terms)
示例#26
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     title_field = self.title_field or self.token_field
     title_getter = self.title_getter or (lambda ob: getattr(ob, title_field))
     for ob in results:
         if ITranslatable.providedBy(ob):
             ob = translate_obj(ob)
         terms.append(vocabulary.SimpleTerm(
                 value = getattr(ob, self.value_field), 
                 token = getattr(ob, self.token_field),
                 title = title_getter(ob),
         ))
     return vocabulary.SimpleVocabulary(terms)
示例#27
0
def get_users_vocabulary():
    session = Session()
    query = session.query(domain.User).order_by(domain.User.last_name,
                                                domain.User.first_name,
                                                domain.User.middle_name)
    results = query.all()
    terms = []
    for ob in results:
        terms.append(
            vocabulary.SimpleTerm(
                value=getattr(ob, 'user_id'),
                token=getattr(ob, 'user_id'),
                title="%s %s" %
                (getattr(ob, 'first_name'), getattr(ob, 'last_name'))))
    return vocabulary.SimpleVocabulary(terms)
示例#28
0
    def __init__(self, context):
        # Retrieve the control panel setting
        registry = getUtility(IRegistry)
        setting = registry[ISponsorshipSettings.__identifier__ +
                           '.levels'] or ()

        # Assemble the terms and add attributes for the amount and
        # optionally the maximum
        terms = []
        for idx, level in enumerate(setting):
            if not level:  # no levels configured
                continue
            level = level.split(',')
            if len(level) < 3:  # improperly configured
                continue
            name = level[0]
            amount = int(level[1])
            term = vocabulary.SimpleTerm(idx,
                                         title=u'%s - $%s' % (name, amount))
            term.name = name
            term.amount = amount
            if len(level) == 3:
                term.maximum = int(level[2])
            terms.append(term)

        # Let the vocabulary finish assembly, including the by_value
        # mapping we need below for getTerm()
        super(SimpleVocabulary, self).__init__(terms)

        # Collect and count the sponsors for each level
        self.counts = counts = {}
        catalog = getToolByName(context, 'portal_catalog')
        for brain in catalog(path='/'.join(context.getPhysicalPath()),
                             portal_type='collective.sponsorship.sponsor',
                             review_state='published',
                             sort_on='getObjPositionInParent'):
            sponsor = brain.getObject()
            idx = sponsor.level
            # XXX: I am not 100% whats going on here but if there
            # is no level then this block needs an if and it works
            if idx:
                term = self.getTerm(idx)
                if not hasattr(term, 'sponsors'):
                    term.sponsors = []
                term.sponsors.append(sponsor)
                if hasattr(term, 'maximum'):
                    count = counts.get(idx, 0) + 1
                    counts[idx] = count
示例#29
0
    def _constructVocabulary(self, value):
        terms = []
        if value:
            for item in value:
                if item and '|' in item:
                    voc_value, voc_title = item.split('|', 1)
                else:
                    voc_value = item
                    voc_title = item

                term = vocabulary.SimpleTerm(
                    token=voc_value.encode('unicode_escape'),
                    value=voc_value,
                    title=voc_title)
                terms.append(term)

        return vocabulary.SimpleVocabulary(terms)
示例#30
0
 def buildTerms(self):
     vocabulary_terms = []
     template_folder = capi.get_path_for("reporting", "templates",
                                         self.template_folder)
     if not os.path.exists(template_folder):
         log.error("Directory for XHTML templates does not exist: %s",
                   template_folder)
         return
     file_list = filter(lambda fname: fname.endswith(".html"),
                        os.listdir(template_folder))
     for file_name in file_list:
         file_path = "/".join([template_folder, file_name])
         vocabulary_terms.append(
             vocabulary.SimpleTerm(file_path,
                                   token=hashlib.md5(file_name).hexdigest(),
                                   title=self.getTitle(file_path)))
     return vocabulary_terms