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)
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)
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)
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)
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)
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)
def __call__(self, context): wft = getToolByName(context, 'portal_workflow') return vocabulary.SimpleVocabulary([ vocabulary.SimpleVocabulary.createTerm(t['id'], t['id'], _(t['name'])) for t in wft.getTransitionsFor(context) ])
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)
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 __call__(self, context): terms = [] for term in self.terms: terms.append(vocabulary.SimpleVocabulary.createTerm(term[0], term[0], term[1])) return vocabulary.SimpleVocabulary(terms)
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)
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
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)
def OrderStorageVocabulary(context): """Returns a vocabulary of the currently registered utilities that implement IOrderStorage. """ # context is the portal config options, whose context is the portal order_storages = getUtilitiesFor(IOrderStorage) terms = create_terms_from_adapters(order_storages) directlyProvides(OrderStorageVocabulary, IVocabularyFactory) return vocabulary.SimpleVocabulary(terms)
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)
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)
def StatusSetsVocabulary(context): """Returns a vocabulary of the currently registered utilities that implement IStatusSet. """ # context is the portal config options, whose context is the portal status_sets = getAdapters((context, ), IStatusSet) terms = create_terms_from_adapters(status_sets) directlyProvides(StatusSetsVocabulary, IVocabularyFactory) return vocabulary.SimpleVocabulary(terms)
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)
def ContactInfoStepGroups(context): """Returns a vocabulary of the registered StepGroups for the contact information StepGroup """ request = getSite().REQUEST # context is the portal config options, whose context is the portal contact_info_step_groups = getAdapters((context, request, context), IContactInformationStepGroup) terms = create_terms_from_adapters(contact_info_step_groups) directlyProvides(ContactInfoStepGroups, IVocabularyFactory) return vocabulary.SimpleVocabulary(terms)
def ShippingAddressStepGroups(context): """Returns a vocabulary of the registered StepGroups for the shipping address StepGroup """ # context is the portal config options, whose context is the portal request = getSite().REQUEST shipping_address_step_groups = getAdapters((context, request, context), IShippingAddressStepGroup) terms = create_terms_from_adapters(shipping_address_step_groups) directlyProvides(ShippingAddressStepGroups, IVocabularyFactory) return vocabulary.SimpleVocabulary(terms)
def OrderReviewStepGroups(context): """Returns a vocabulary of the registered StepGroups for the order review StepGroup """ # context is the portal config options, whose context is the portal request = getSite().REQUEST order_review_step_groups = getAdapters((context, request, context), IOrderReviewStepGroup) terms = create_terms_from_adapters(order_review_step_groups) directlyProvides(OrderReviewStepGroups, IVocabularyFactory) return vocabulary.SimpleVocabulary(terms)
def PaymentProcessors(context): """Returns a vocabulary of the registered PaymentProcessors """ # context is the portal config options, whose context is the portal request = getSite().REQUEST payment_processors = getAdapters((context, request, context), IPaymentProcessor) terms = create_terms_from_adapters(payment_processors) directlyProvides(PaymentProcessors, IVocabularyFactory) return vocabulary.SimpleVocabulary(terms)
def languages_vocabulary_factory(context): parent = aq_parent(context) if IATContentType.providedBy(parent): selected = parent.Schema()['language_constraint'].get(parent) languages = languages_vocabulary_factory(parent) filtered = [] for term in languages: if not term.value in selected: continue filtered.append(term) return vocabulary.SimpleVocabulary(filtered) return getUtility(IVocabularyFactory, 'plone.app.vocabularies.SupportedContentLanguages')(parent)
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)
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)
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)
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)
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)
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)
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"))})), ))