[Grok-dev] re gistering vocabulary

Sebastian Ware sebastian at urbantalk.se
Mon May 9 05:41:16 EDT 2011


We use vocabularies extensively in out applications in all version including 1.3. This is how we create and register a vocabulary. This is all the code we write and in the interface we put:

visibility = schema.Choice(title=u'Visibility', vocabulary="visibility", default = 'private')


# Defining the vocabulary...

_visibility = (
               ('private', 'Private'),
               ('public', 'Public')
               )
class Visibility(grok.GlobalUtility):
    grok.implements(IVocabularyFactory)
    grok.name(u'visibility')
    def __call__(self, context):
        terms = self.get_categories(context)
        return  SimpleVocabulary(terms)
    
    def get_categories(self, context):
        hasItem = {}
        theList = []
        for item in _visibility:
            key = item[0]
            title = item[1]
            theList.append(SimpleVocabulary.createTerm(key, key, title))
            hasItem[key] = True
        
        tmp = getattr(context, 'visibility', None)
        if tmp is not None and not hasItem.has_key(tmp):
            # It fails if the current value isn't found
            theList.append(SimpleVocabulary.createTerm(tmp, tmp, u'Option %s removed! (contact developer)' % tmp))
        return theList

Mvh Sebastian

9 maj 2011 kl. 11.24 skrev Jeroen Michiel:

> 
> Seems the same in v1.3...
> This is a major issue for me, if I can't use my vocabularies!
> -- 
> View this message in context: http://old.nabble.com/registering-vocabulary-tp31388474p31575239.html
> Sent from the Grok mailing list archive at Nabble.com.
> 
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev
> 



More information about the Grok-dev mailing list