Example #1
0
def lookupVocabulary(context, field):
    if IVocabulary.providedBy(field.vocabulary):
        return field.vocabulary.getVocabularyDict(context)
    else:
        vocab = field.Vocabulary(context)
        tree = OrderedDict()
        for key in vocab:
            tree[key] = vocab.getValue(key)
        return tree
Example #2
0
def lookupVocabulary(context, field):
    if IVocabulary.providedBy(field.vocabulary):
        return field.vocabulary.getVocabularyDict(context)
    else:
        vocab = field.Vocabulary(context)
        tree = OrderedDict()
        for key in vocab:
            tree[key] = vocab.getValue(key)
        return tree
 def getVocabulary(self, instance):
     """ return the vocabulary by name from atvocabularymanager
     """
     vt = getToolByName(instance, TOOL_NAME)
     vocab = vt.getVocabularyByName(self.vocab_name)
     if vocab is None:
         raise KeyError('Vocabulary id not found in ' + \
             'portal_vocabularies : %s' % self.vocab_name)        
     assert(IVocabulary.providedBy(vocab))
     return vocab
Example #4
0
 def getVocabulary(self, instance):
     """ return the vocabulary by name from atvocabularymanager
     """
     vt = getToolByName(instance, TOOL_NAME)
     vocab = vt.getVocabularyByName(self.vocab_name)
     if vocab is None:
         raise KeyError('Vocabulary id not found in ' + \
             'portal_vocabularies : %s' % self.vocab_name)        
     assert(IVocabulary.providedBy(vocab))
     return vocab
    def getVocabulary(self, instance):
        """ Gets this column vocabulary for specific Archetypes instance
        """
        if IVocabulary.providedBy(self.vocabulary):
            return self.vocabulary.getDisplayList(instance)
        try:
            func = getattr(instance, self.vocabulary)
        except AttributeError:
            raise AttributeError, "Class %s is missing vocabulary function %s" % (str(instance), self.vocabulary)

        return func()
    def getVocabulary(self, instance):
        """ Gets this column vocabulary for specific Archetypes instance
        """
        if IVocabulary.providedBy(self.vocabulary):
            return self.vocabulary.getDisplayList(instance)
        try:
            func = getattr(instance, self.vocabulary)
        except AttributeError:
            func = instance.restrictedTraverse(self.vocabulary, None)
            if func is None:
                raise AttributeError, "Class %s is missing vocabulary function %s" % (str(instance), self.vocabulary)

        return func()
Example #7
0
 def __call__(self):
     fieldname = self.request.get('fieldname')
     field = self.context.Schema()[fieldname]
     import pdb; pdb.set_trace()
     if IVocabulary.providedBy(field.vocabulary):
         tree = field.vocabulary.getVocabularyDict(self.context)
     else:
         vocab = field.Vocabulary(self.context)
         tree = OrderedDict()
         for key in vocab:
             tree[key] = vocab.getValue(key)
     tree = dict2dynatree(tree, lambda x: True, lambda x: True)
     return JSONWriter().write(tree)
Example #8
0
    def __call__(self):
        self.form = deepcopy(self.default_query)
        self.form.update(deepcopy(self.request.form))

        catalog = getToolByName(self.context, 'portal_catalog')
        query = deepcopy(self.form)
        self.results = catalog(query)

        facet_counts = getattr(self.results, 'facet_counts', {})
        voctool = getToolByName(self.context, 'portal_vocabularies', None)
        self.vocDict = dict()

        for field in self.facet_fields:
            voc = {}
            if voctool:
                voc = voctool.getVocabularyByName(field)
            if IVocabulary.providedBy(voc):
                self.vocDict[field] = ( voc.Title(), 
                                        voc.getVocabularyDict(self.context))
            elif facet_counts: 
                # we don't have a matching vocabulary, so we fake one
                before = after = -1
                if field in facet_counts['facet_fields']:
                    field_values = facet_counts['facet_fields'][field].keys()

                elif field in facet_counts['facet_ranges']:
                    field_values= facet_counts['facet_ranges'][field]['counts'].keys()
                    before = facet_counts['facet_ranges'][field].get('before', -1)
                    after = facet_counts['facet_ranges'][field].get('after', -1)
                else:
                    continue

                content = dict()
                if before >= 0:
                    content[DATE_LOWERBOUND] = ('Before', None)
                if after >= 0:
                    content[DATE_UPPERBOUND] = ('After', None)

                for value in field_values:
                    content[value] = (self.getFriendlyValue(field, value), None)

                self.vocDict[field] = (self.getFriendlyFieldName(field), content)