[Zope-dev] disabling zope.schema constraint check in edit form

Joshua Immanuel josh at hipro.co.in
Thu Aug 18 03:59:56 EDT 2011


Hello all,

I use the zope.schema field's constraint parameter to check for the
uniqueness of a particular field like this

        class IMyObject(Interface):
        
                def check_for_uniqueness(value):
                        cat = getUtility(ICatalog)
                        results = cat.searchResults(object_name=value)
                        for rslt in results:
                                if rslt.name.lower() == value.lower():
                                        raise NameAlreadyExists(value)
                        return True
                        
                name = TextLine(title=u'Name', required=True,
                		constraint=check_for_uniqueness)
                ...
                
This goes well with the zope.formlib's AddForm. But in edit form if I
modify any other field other than the 'name' field I get the
'NameAlreadyExists' error. Worse case scenario is where I have a cancel
action button which just redirects to another page, that too screams for
the NameAlreadyExists error.

Is there a way to disable the constraint check in the EditForm if the
'name' field isn't modified?

What is the preferred way of doing these kind of checks?

Please guide me.

-- 
Joshua Immanuel
HiPro IT Solutions Private Limited
http://hipro.co.in
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20110818/3541a280/attachment.bin 


More information about the Zope-Dev mailing list