def languages(self):
        """Vocabulary method for the language field
        """
        util = None

        use_combined = False
        # Respect the combined language code setting from PloneLanguageTool
        lt = getToolByName(self, 'portal_languages', None)
        if lt is not None:
            use_combined = lt.use_combined_language_codes

        # Try the utility first
        if HAS_PLONE_I18N:
            util = queryUtility(IMetadataLanguageAvailability)
        # Fall back to acquiring availableLanguages
        if util is None:
            languages = getattr(self, 'availableLanguages', None)
            if callable(languages):
                languages = languages()
            # Fall back to static definition
            if languages is None:
                return DisplayList(
                    (('en', 'English'), ('fr', 'French'), ('es', 'Spanish'),
                     ('pt', 'Portuguese'), ('ru', 'Russian')))
        else:
            languages = util.getLanguageListing(combined=use_combined)
            languages.sort(key=lambda x: x[1])
            # Put language neutral at the top.
            languages.insert(0, (u'', _(u'Language neutral')))
        return DisplayList(languages)
Exemplo n.º 2
0
 def getNaceList(self):
     """See interface"""
     result = DisplayList()
     pv = getToolByName(self, 'portal_vocabularies')
     VOCAB = getattr(pv, 'NACE', None)
     if not VOCAB:
         return result
     vd = VOCAB.getVocabularyDict(self)
     result = DisplayList()
     for k in vd.keys():
         result.add(k, vd[k][0])
     return result
Exemplo n.º 3
0
 def test_cmp(self):
     ta = ('a', 'b', 'c')
     tb = ('a', 'c', 'b')
     td = ('c', 'b', 'a')
     self.assertTrue(DisplayList(zip(ta, ta)) == DisplayList(zip(ta, ta)))
     self.assertFalse(DisplayList(zip(ta, ta)) == DisplayList(zip(ta, tb)))
     self.assertTrue(DisplayList(zip(ta, ta)) == DisplayList(zip(td, td)))
     self.assertTrue(DisplayList(zip(tb, ta)) == DisplayList(zip(tb, ta)))
     self.assertRaises(TypeError, cmp, DisplayList(), '')
Exemplo n.º 4
0
    def test_sort(self):
        a = (('a', 'a',), ('b', 'b'), ('c', 'c'))
        b = (('z', 'Z',), ('y', 'Y'), ('x', 'X'))
        c = (('a', 'Z',), ('c', 'Y'), ('b', 'X'))
        dla = DisplayList(a)
        dlb = DisplayList(b)
        dlc = DisplayList(c)

        assert dla.values() == ['a', 'b', 'c']
        dlb_s = dlb.sortedByValue()
        assert dlb_s.values() == ['X', 'Y', 'Z']
        dlc_s = dlc.sortedByKey()
        assert dlc_s.values() == ['Z', 'X', 'Y']
 def getMemberTypesVocab(self):
     """ Get a displaylist of remember-based member types.
     """
     remtypes = getRememberTypes(self)
     remtypes.sort()
     remtypes = [(i, i) for i in remtypes]
     return DisplayList(remtypes)
Exemplo n.º 6
0
 def normVocabulary(self):
     normTypes = DisplayList()
     normTypes.add('', _(u'-- not specified --'))
     for normType in self.aq_parent.getNorma_o_titolo():
         normTypes.add(normType, normType)
     normTypes.add('other', _(u'other'))
     return normTypes
Exemplo n.º 7
0
 def awardProceduresVocab(self):
     """ """
     award_procedures = DisplayList()
     award_procedures.add('', _(u'-- not specified --'))
     for award_procedure in self.aq_parent.getModalita_affidamento():
         award_procedures.add(award_procedure, award_procedure)
     return award_procedures
Exemplo n.º 8
0
 def officeVocab(self):
     """ """
     offices = DisplayList()
     offices.add('', _(u'-- not specified --'))
     for office in self.aq_parent.getElenco_uffici():
         offices.add(office, office)
     return offices
Exemplo n.º 9
0
    def _initStringValidators(self):
        """ Initialize string validators from config
        """

        self.stringValidators = {}
        self.stringValidatorsDL = DisplayList()
        self.stringValidatorsDL.add('vocabulary_none_text', u'None')

        for kwa in config.stringValidators:
            id = kwa['id']

            title = kwa.get('title', id)
            i18nid = kwa.get('i18nid', title)

            errmsg = kwa.get('errmsg', 'Validation failed: %s' % id)
            errid = kwa.get('errid', errmsg)
            errmsg = _(errid, errmsg)

            validatorId = 'pfgv_%s' % id
            self.stringValidators[id] = {
                'title'  : title,
                'i18nid' : i18nid,
                'errmsg' : errmsg,
                'errid'  : errid,
                # 'revalid': revalid,
                'id'     : validatorId,
                }

            self.stringValidatorsDL.add( id, title, msgid=i18nid )
Exemplo n.º 10
0
    def _Vocabulary(self, content_instance):
        pairs = []
        pc = getToolByName(content_instance, 'portal_catalog')

        allowed_types = self.allowed_types
        allowed_types_method = getattr(self, 'allowed_types_method', None)
        if allowed_types_method:
            meth = getattr(content_instance, allowed_types_method)
            allowed_types = meth(self)

        skw = allowed_types and {'portal_type': allowed_types} or {}
        pc_brains = pc.searchResults(**skw)

        if self.vocabulary_custom_label is not None:
            label = lambda b: eval(self.vocabulary_custom_label, {'b': b})
        elif self.vocabulary_display_path_bound != -1 and len(
                pc_brains) > self.vocabulary_display_path_bound:
            at = _(u'label_at', default=u'at')
            label = lambda b: u'%s %s %s' % (self._brains_title_or_id(
                b, content_instance), at, b.getPath())
        else:
            label = lambda b: self._brains_title_or_id(b, content_instance)

        for b in pc_brains:
            pairs.append((str(b.intid), label(b)))

        if not self.required and not self.multiValued:
            no_reference = _(u'label_no_reference', default=u'<no reference>')
            pairs.insert(0, ('', no_reference))

        __traceback_info__ = (content_instance, self.getName(), pairs)
        __traceback_info__  # pyflakes
        return DisplayList(pairs)
Exemplo n.º 11
0
    def getAtividades(self, id):
        listAtividade = DisplayList()
        if id != '':
            url = self.getURLWebservice()
            client = Client(url)
            filtro = client.factory.create('wsFiltros')

            if id == '1':
                self.idTipoServico = 1
                self.siglaTipoServico = "INFR"
            if id == '2':
                self.idTipoServico = 2
                self.siglaTipoServico = "CRTL"
            if id == '3':
                self.idTipoServico = 3
                self.siglaTipoServico = "SUST"
            if id == '4':
                self.idTipoServico = 4
                self.siglaTipoServico = "PLAN"

            filtro.tipoServico.id = self.idTipoServico
            filtro.tipoServico.sigla = self.siglaTipoServico
            search = client.service.consultarAtividades(filtro)

            if search:
                item = search.item
                for item in item:
                    listAtividade.add('', '')
                    atividade = item.listAtividade[0]
                    codAtividade = atividade.codigo
                    descAtividade = atividade.codigo + ' - ' + atividade.descricao
                    #self.descricaoAtividade = descAtividade
                    listAtividade.add(codAtividade, descAtividade)
            listAtividade = listAtividade.sortedByValue()
        return listAtividade
Exemplo n.º 12
0
 def getReportersForSittingVocab(self):
     """ Get the current parliament's team of reporters, and return
     the active memberships.
     """
     rota_tool = getToolByName(self, 'portal_rotatool')
     members = rota_tool.getAvailableReporters()
     return DisplayList([(m.UID(), m.Title()) for m in members])
Exemplo n.º 13
0
    def vocNumeroAppuntamenti(self):
        """
        """
        res = DisplayList()
        for x in range(0, 21):
            res.add(str(x), str(x))

        return res
Exemplo n.º 14
0
 def getSubjectList(self):
     """See interface"""
     pc = getToolByName(self, 'portal_catalog')
     vals = pc.uniqueValuesFor('Subject')
     result = DisplayList()
     for v in vals:
         result.add(v, v)
     return result
Exemplo n.º 15
0
 def getDisplayListFor(self, vocabularyName=''):
     """See interface"""
     pv = getToolByName(self, 'portal_vocabularies')
     VOCAB = getattr(pv, vocabularyName, None)
     if not VOCAB:
         return DisplayList()
     DL = VOCAB.getDisplayList(self)
     return DL
Exemplo n.º 16
0
 def test_add(self):
     ta = ('a', 'b', 'c')
     l = zip(ta, ta)
     dl = DisplayList(l)[:]
     self.assertTrue(dl == l)
     l.append(('d', 'd'))
     dl.append(('d', 'd'))
     self.assertTrue(dl == l)
Exemplo n.º 17
0
    def getSampleTypes(self):
        """ return all sampletypes """
        sampletypes = []
        bsc = getToolByName(self, 'bika_setup_catalog')
        for st in bsc(portal_type='SampleType', sort_on='sortable_title'):
            sampletypes.append((st.UID, st.Title))

        return DisplayList(sampletypes)
Exemplo n.º 18
0
 def test_call(self):
     ta = ('a', 'b', 'c')
     l = zip(ta, ta)
     dl = DisplayList(l)
     self.assertTrue(dl == dl)
     self.assertTrue(dl() == dl())
     self.assertTrue(dl[:] == l)
     self.assertTrue(dl()[:] == l)
Exemplo n.º 19
0
 def getElencoTipologie(self):
     """ restituisce l'elenco delle tipologie sulla folder padre
     """
     elenco_tipologie = DisplayList()
     items = self.getPrenotazioniFolder().getTipologia()
     for item in items:
         elenco_tipologie.add(item, item)
     return elenco_tipologie
Exemplo n.º 20
0
 def _getCalculations(self):
     """Available Calculations registered in Setup
     """
     bsc = getToolByName(self, "bika_setup_catalog")
     items = [(c.UID, c.Title)
              for c in bsc(portal_type="Calculation", is_active=True)]
     items.sort(lambda x, y: cmp(x[1], y[1]))
     items.insert(0, ("", t(_("None"))))
     return DisplayList(items)
Exemplo n.º 21
0
 def getAnalysisCategories(self):
     """ return all available analysis categories """
     bsc = getToolByName(self, 'bika_setup_catalog')
     cats = []
     for st in bsc(portal_type='AnalysisCategory',
                   inactive_state='active',
                   sort_on='sortable_title'):
         cats.append((st.UID, st.Title))
     return DisplayList(cats)
Exemplo n.º 22
0
 def getContactsDisplayList(self):
     wf = getToolByName(self, 'portal_workflow')
     pairs = []
     for contact in self.objectValues('Contact'):
         if wf.getInfoFor(contact, 'inactive_state', '') == 'active':
             pairs.append((contact.UID(), contact.Title()))
     # sort the list by the second item
     pairs.sort(lambda x, y: cmp(x[1], y[1]))
     return DisplayList(pairs)
Exemplo n.º 23
0
 def _getLabContacts(self):
     bsc = api.get_tool("bika_setup_catalog")
     # fallback - all Lab Contacts
     pairs = [["", ""]]
     for contact in bsc(portal_type="LabContact",
                        is_active=True,
                        sort_on="sortable_title"):
         pairs.append((contact.UID, contact.Title))
     return DisplayList(pairs)
Exemplo n.º 24
0
 def getAnalysisServices(self):
     """
     """
     bsc = getToolByName(self, 'bika_setup_catalog')
     items = [('', '')] + [(o.UID, o.Title) for o in
                           bsc(portal_type='AnalysisService',
                               inactive_state='active')]
     items.sort(lambda x, y: cmp(x[1], y[1]))
     return DisplayList(list(items))
Exemplo n.º 25
0
 def getContacts(self):
     bsc = getToolByName(self, 'bika_setup_catalog')
     # fallback - all Lab Contacts
     pairs = []
     for contact in bsc(portal_type='LabContact',
                        inactive_state='active',
                        sort_on='sortable_title'):
         pairs.append((contact.UID, contact.Title))
     return DisplayList(pairs)
Exemplo n.º 26
0
    def _getAvailableInstrumentsDisplayList(self):
        """Available instruments registered in the system

        Only instruments with state=active will be fetched
        """
        bsc = getToolByName(self, "bika_setup_catalog")
        items = [(i.UID, i.Title)
                 for i in bsc(portal_type="Instrument", is_active=True)]
        items.sort(lambda x, y: cmp(x[1], y[1]))
        return DisplayList(list(items))
Exemplo n.º 27
0
 def getContacts(self, dl=True):
     pairs = []
     objects = []
     for contact in self.aq_parent.objectValues('Contact'):
         if isActive(contact) and contact.UID() != self.UID():
             pairs.append((contact.UID(), contact.Title()))
             if not dl:
                 objects.append(contact)
     pairs.sort(lambda x, y: cmp(x[1].lower(), y[1].lower()))
     return dl and DisplayList(pairs) or objects
Exemplo n.º 28
0
    def lookupTemplates(self, instance_or_portaltype=None):
        # Lookup templates by giving an instance or a portal_type.
        # Returns a DisplayList.
        results = []
        if not isinstance(instance_or_portaltype, basestring):
            portal_type = instance_or_portaltype.getTypeInfo().getId()
        else:
            portal_type = instance_or_portaltype
        try:
            templates = self._templates[portal_type]
        except KeyError:
            return DisplayList()
            # XXX Look this up in the types tool later
            # self._templates[instance] = ['base_view',]
            # templates = self._templates[instance]
        for t in templates:
            results.append((t, self._registeredTemplates[t]))

        return DisplayList(results).sortedByValue()
Exemplo n.º 29
0
 def getAnalysisCategories(self):
     """Return all available analysis categories
     """
     bsc = api.get_tool("bika_setup_catalog")
     cats = []
     for st in bsc(portal_type="AnalysisCategory",
                   is_active=True,
                   sort_on="sortable_title"):
         cats.append((st.UID, st.Title))
     return DisplayList(cats)
Exemplo n.º 30
0
 def getAnalysisServicesVocabulary(self):
     """
     Get all active Analysis Services from Bika Setup and return them as Display List.
     """
     bsc = getToolByName(self, 'bika_setup_catalog')
     brains = bsc(portal_type='AnalysisService', inactive_state='active')
     items = [(b.UID, b.Title) for b in brains]
     items.insert(0, ("", ""))
     items.sort(lambda x, y: cmp(x[1], y[1]))
     return DisplayList(list(items))