def get_parliamentary_term(self, val): """ Return legislative type label for a given value """ vocabulary = NamedVocabulary("org.bungeni.metadata.vocabularies.parliamentarytypes") returnVal = None try: if vocabulary.getVocabularyDict(self)[val][0]: returnVal = vocabulary.getVocabularyDict(self)[val][0] except: returnVal = None return returnVal
def __call__(self): fieldname = self.request.get('fieldname') #field = self.context.schema[fieldname] # TODO: This is hardcoded, Incredibly stupid, needs to change. atv = NamedVocabulary('staralliance.productcategories') tree = atv.getVocabularyDict(self.context) selected = self.request.get('selected', []).split('|') return JSONWriter().write(dict2dynatree(tree, selected, True, False))
def rows(self, names): output = [] wftool = self.wftool checkPermission = getSecurityManager().checkPermission credit_utils = self.context.unrestrictedTraverse('@@credit_utils') atvm = api.portal.get_tool(name='portal_vocabularies') nv = NamedVocabulary('ancient-name-languages') lang_vocab = nv.getVocabularyDict(atvm) for score, ob, nrefs in sorted(names, key=lambda k: k[1].Title() or ''): nameAttested = ob.getNameAttested() or None title = ob.Title() or "Untitled" if nameAttested: label, label_class = unicode( nameAttested, "utf-8"), "nameAttested" else: label, label_class = unicode( title, "utf-8"), "nameUnattested" labelLang = ob.getNameLanguage() or "und" review_state = wftool.getInfoFor(ob, 'review_state') item = u'<span lang="%s">%s</span>' % ( labelLang, label + u" (copy)" * ("copy" in ob.getId()), ) if checkPermission('View', ob): link = '<a class="state-%s %s" href="%s">%s</a>' % ( review_state, label_class, ob.absolute_url(), item) else: link = '<span class="state-%s %s">%s</span>' % ( review_state, label_class, item) if review_state != 'published': user = credit_utils.user_in_byline(ob.Creator()) status = u' [%s by %s]' % (review_state, user['fullname'].decode('utf-8')) else: status = u'' if labelLang != "und": lang_title = lang_vocab[labelLang] else: lang_title = None innerHTML = [ u'<li id="%s" class="placeChildItem" title="%s">' % ( ob.getId(), self.snippet(ob)), self.prefix(ob), link, self.postfix(ob, lang_title), status, u'</li>', ] output.append(u"\n".join(innerHTML)) return output
def testNamedVocab(self): self.setupSimpleVocabulary() svtest = self.atvm.svtest nv = NamedVocabulary(self.vname) # vocabs are the same self.assertEqual(nv.getVocabulary(self.atvm), svtest) vocab = svtest.getVocabularyDict() # dict vocab are the same self.assertEqual(nv.getVocabularyDict(self.atvm), vocab) # 5 items in place self.assertEqual(len(svtest), len(nv.getVocabulary(self.atvm)), 5) # in display list too self.assertEqual(len(nv.getDisplayList(self.atvm)), 5) # let's test `empty_first_item` option nv1 = NamedVocabulary(self.vname, empty_first_item=1) # vocab are still the same self.assertEqual(nv1.getVocabulary(self.atvm), svtest) # 5 items in place self.assertEqual(len(nv1.getVocabulary(self.atvm)), 5) # but 6 items in display list dlist = nv1.getDisplayList(self.atvm) self.assertEqual(len(dlist), 6) # and we have an empty item on top empty_item = (u'', u'--') self.failUnless(empty_item in dlist.items()) self.assertEqual(empty_item, dlist.items()[0]) # now use a `custom_empty_first_item` custom_item = (u'foo', u'Foo') nv2 = NamedVocabulary(self.vname, empty_first_item=1, custom_empty_first_item=[custom_item]) # vocab are still the same self.assertEqual(nv2.getVocabulary(self.atvm), svtest) # 5 items in place self.assertEqual(len(nv2.getVocabulary(self.atvm)), 5) # but 6 items in display list dlist = nv2.getDisplayList(self.atvm) self.assertEqual(len(dlist), 6) # and we have an empty item on top self.failUnless(custom_item in dlist.items()) self.assertEqual(custom_item, dlist.items()[0])
def archive(self, context, initiator=None, reason=None, custom_message=None, archive_date=None): """Archive the object :param context: given object that should be archived :param initiator: the user id or name which commissioned the archival :param reason: reason id for which the object was archived :param custom_message: Custom message explaining why the object was archived :param archive_date: DateTime object which sets the expiration date of the object """ initiator = safe_unicode(initiator) reason = safe_unicode(reason) custom_message = safe_unicode(custom_message) wftool = getToolByName(context, 'portal_workflow') has_workflow = wftool.getChainFor(context) if not has_workflow: # NOP return date = archive_date if archive_date else DateTime() alsoProvides(context, IObjectArchived) context.setExpirationDate(date) # refactor this setting from here, without these assignments to self # the test for is_archived fails self.archive_date = date self.initiator = initiator self.custom_message = custom_message self.reason = reason state = wftool.getInfoFor(context, 'review_state') mtool = getToolByName(context, 'portal_membership') actor = mtool.getAuthenticatedMember().getId() rv = NamedVocabulary('eea.workflow.reasons') vocab = rv.getVocabularyDict(context) reason = vocab.get(reason, "Other") if custom_message: reason += u" (%s)" % custom_message comments = (u"Archived by %(actor)s on %(date)s by request " u"from %(initiator)s with reason: %(reason)s" % { 'actor': actor, 'initiator': initiator, 'reason': reason, 'date': date.ISO8601() }) for wfname in context.workflow_history.keys(): history = context.workflow_history[wfname] history += ({ 'action': 'Archive', 'review_state': state, 'actor': actor, 'comments': comments, 'time': date, },) context.workflow_history[wfname] = history context.workflow_history._p_changed = True context.reindexObject() notify(ObjectModifiedEvent(context))
def getPsterm(self): vocab = NamedVocabulary("PSSemesters") try: displayval = vocab.getVocabularyDict(self)[self.psterm] except KeyError, e: retstr = ""
def getServiceType(self, component): serviceType = component.getService_type() vocabulary = NamedVocabulary('service_types') vocabulary = vocabulary.getVocabularyDict(component) return vocabulary[serviceType]
def __call__(self, context): atv = NamedVocabulary('NACE') vocab = atv.getVocabularyDict(getSite()) tree = _createTermTree(TreeVocabulary.terms_factory(), vocab) return TreeVocabulary(tree)