[Grok-dev] Values from another document before rendering

Kathy Manwaring kathy at perfectnotes.com.au
Fri Feb 12 06:39:44 EST 2010


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