[Grok-dev] Values from another document before rendering
kathy at perfectnotes.com.au
Fri Feb 12 06:54:13 EST 2010
There may be a number of 'site' entries:
It determines which of the branches controls the values returned.
Is it possible?
P.S. Sorry - bed time on Fri night. I will look at this tomorrow - hoping
someone can help me. :-)
> 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:
>> country = schema.Choice(
>> description=u"The seller's Country.",
>> class CountryChoicesSource(grok.GlobalUtility):
>> 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
>> 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
>> return list_Of_Vals
>> My issue is that my context above does not have the attribute that I
>> it to have - I need to know what the site value on the form is - but it
>> does not seem to be present.
More information about the Grok-dev