[Grok-dev] unique item in container question
    Christian Klinger 
    cklinger at novareto.de
       
    Tue Mar 17 05:53:08 EDT 2009
    
    
  
Hi modiadi,
in zope3 there is a concept called NamedChooser. You can look here [1]
for the default implementation. Of course you can override the 
NameChooser for your NewsContainer so you can check if the news item 
already exists.
There is an example in Philipp´s *Web Component Development with Zope3*.
Hope this helps
- Christian
[1] 
http://svn.zope.org/zope.container/trunk/src/zope/container/contained.py?rev=97508&view=auto
> Hello,
> 
> I have a grok.AddForm wich adds a NewsItem in a NewsContainer. I try  
> to write some kind of validation so I dont have duplicate news in the  
> container.
> 
> As I see I have 3 a few options:
> 
> 1. Write an invariant in the NewsItem model where I check if the news  
> is unique in the *container*. I don't see this as a good option  
> because I have to explicitly refer to the container in side a model.
> 
> 2. Write the validation in the Add grok.action. The idea is that just  
> before adding the new item in the container I check if I have  
> duplicates. This was easy to do.
> 
> My problem is that I can't(or I don't know how to) return an error to  
> the user from this place.
> 
>      @grok.action('Add event')
>        def add(self,**data):
>            ...... do some validation
> 	  return None?
> 
> Do you have any suggestions ?
> 
> Thank you !
    
    
More information about the Grok-dev
mailing list