[Grok-dev] Values from another document before rendering

Souheil CHELFOUH trollfot at gmail.com
Fri Feb 12 06:47:23 EST 2010


Using this code, the context given to the vocabulary will be the
context on which the form is called.
You won't be able to access the form object from there.

What is this "site" attribute, and what impact does it have on the vocabulary ?

2010/2/12 Kathy Manwaring <kathy at perfectnotes.com.au>:
> OK - here is what I need to have happen:
>
> interface:
>    country = schema.Choice(
>        title=u'Country',
>        description=u"The seller's Country.",
>        vocabulary=u'CountryChoices',
>        required=True
>    )
>
> vocabulary:
> class CountryChoicesSource(grok.GlobalUtility):
>    grok.implements(schema.interfaces.IVocabularyFactory)
>    grok.name('CountryChoices')
>
>    def __call__(self, context):
>        #get the entries
>        #return a vocabulary of the types
>        terms = self.get_country_choices(context)
>        return SimpleVocabulary(terms)
>
>    def get_country_choices(self, context):
>        print 'context:',
>        print context #this is a grok.Container
>        print 'name:',
>        print context.__name__ # this gives the form name as expected
>        print 'hasattr?',
>        if hasattr(context, 'site'): # and context.site is not None:
>            print 'site:',
>            print context.site
>        else:
>            print 'no' #prints this line
>        list_Of_Vals = []
>        vals = grok.getSite()['eBayCountries']
>        item_List = vals.keys()
>        if item_List is not None:
>            for key in item_List:
>                value = vals[key]
>                term = value.desc
>                val = key.encode('utf-8')
>                val += u' - ' + term
>                list_Of_Vals.append(UnicodeVocabulary.createUnicodeTerm(val,
>                                                                        val,
>                                                                        val))
>        return list_Of_Vals
>
> My issue is that my context above does not have the attribute that I need
> it to have - I need to know what the site value on the form is - but it
> does not seem to be present.
>
> Thanks,
>
> Kathy
>
>
>


More information about the Grok-dev mailing list