[Grok-dev] Values from another document before rendering

Souheil CHELFOUH trollfot at gmail.com
Fri Feb 12 06:30:03 EST 2010


Can you repeat your problem ? I don't think I read it, back then.
What do you want to acheive ?

2010/2/12 Kathy Manwaring <kathy at perfectnotes.com.au>:
> OK. I had an issue with getting a vocabulary working, back in November.
>
> The response that you sent me (quoted below) refers to a check for
> gallery_id:
>
> if hasattr(context, 'gallery_id') and context.gallery_id is not None:
>    # I allways need to have the current value in my vocabulary
>    # or choice widgets won't render.
>    hasItem.append(context.gallery_id)
>
> Presumably the call to the vocabulary includes some way of setting the
> value of gallery_id - I can't get a value on my context, so I hope you can
> send me the code for that bit as well!
>
> Hopefully that is clearer - thanks for your time, Sebastian!
>
> Kathy
>
>> I am pretty sure I misunderstood the question...
>>
>> Mvh Sebastian
>
>>>> Sebastian Ware wrote:
>>>>> This is what I do. I have a field defined in an interface:
>>>>>
>>>>> gallery_id = schema.Choice(title=u"Gallery", vocabulary=u"Published
>>>> NewProductGalleries")
>>>>>
>>>>> The vocabulary looks like this (it is a bit dirty, but it might
>>>>> help you
>>>> in the right direction):
>>>>>
>>>>>
>>>>> import grok
>>>>> from zope import schema
>>>>> from zope.schema.vocabulary import SimpleVocabulary
>>>>> from boardsportsource import interfaces
>>>>> from boardsportsource import workflow
>>>>> from hurry import query
>>>>>
>>>>> class NewProductGalleriesSource(grok.GlobalUtility):
>>>>>   grok.implements(schema.interfaces.IVocabularyFactory)
>>>>>   grok.name('Published NewProductGalleries')
>>>>>   def __call__(self, context):
>>>>>       terms = self.get_published_galleries(context)
>>>>>       return  SimpleVocabulary(terms)
>>>>>
>>>>>   def get_published_galleries(self, context):
>>>>>       hasItem = []
>>>>>       if hasattr(context, 'gallery_id') and context.gallery_id is
>>>>> not
>>>> None:
>>>>>           # I allways need to have the current value in my
>>>>> vocabulary
>>>>>           # or choice widgets won't render.
>>>>>           hasItem.append(context.gallery_id)
>>>>>
>>>>>       # I use hurry.query to find the objects I want to use in
>>>>>       # my vocabulary.
>>>>>       theQuery = query.Eq(('workflow_catalog', 'workflow_state'),
>>>> workflow.PUBLISHED)
>>>>>       theQuery = theQuery & query.Eq(('workflow_catalog',
>>>> 'object_type'), 'new_product_gallery')
>>>>>       dictResult = query.query.Query().searchResults(theQuery)
>>>>>
>>>>>       theList = []
>>>>>       for item in dictResult:
>>>>>           theObj = interfaces.INewProductGallery(item)
>>>>>
>>>>> theList.append(SimpleVocabulary.createTerm(theObj.__name__,
>>>> theObj.__name__, '%s (%s)' % (theObj.title, 'default')))
>>>>>           if theObj.__name__ in hasItem:
>>>>>               hasItem.remove(theObj.__name__)
>>>>>
>>>>>       for key in hasItem:
>>>>>           # If the current value wasn't found in the search I add
>>>>> it here
>>>>>           # with an appropriate message.
>>>>>           if grok.getSite()['default'].has_key(key):
>>>>>               theObj =
>>>> interfaces.IImageOfTheDayGallery(grok.getSite()['default'][key])
>>>>>               theList.append(SimpleVocabulary.createTerm(key, key,
>>>>> '%s
>>>> (not published!)' % theObj.title))
>>>>>           else:
>>>>>               theList.append(SimpleVocabulary.createTerm(key, key,
>>>>> '%s
>>>> has been removed!' % key))
>>>>>       return theList
>>>>>
>>>>> Mvh Sebastian
>
> _______________________________________________
> 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