[Zope3-Users] z3c.form: terms/validation and problems with context

2008-08-19 Thread Carsten Senger
I use a session-based wizard with plone.z3cform that uses the concept 
from z3c.formdemo's wizard. The content is kept inside a session until 
it is written into the db in .finish().

I have problems with Lists and Choices where the vocabulary needs a 
suitable context that the content from the session doesn't provide.

By default my Vocabularyfactory fails to get it's data and returns a 
empty SimpleVocabulary. The widget is empty.
I can fill the widget with my terms like that:

 def getTerms(self, factory):
 terms = term.Terms()
 terms.terms =  factory(self.parentForm.context)
 return terms

 def updateWidgets(self):
 super(FachgebieteSchritt, self).updateWidgets()
 self.widgets['key_activities'].terms = \
self.getTerms(cv.KeyActivitiesVocabularyFactory)
 self.widgets['key_activities'].update()


But saving the selected values fails. validator.SimpleFieldValidator 
calls the field's _validate()-Method with the wrong context (the 
content) and WrongContainedType is raised.

My actual solution is to register a NullValidator for wizard.IStep and 
zope.schema.interfaces.I[List|Choice].

Is there a more elegant way, e.g. where updateTerms and 
SimpleFieldValidator.validate() can use the right context?


A second, small problem is that I tried to use the Discriminator like 
the Doctest describes

validator.WidgetValidatorDiscriminators(NullListValidator,
 view=interfaces.IStep,
 field=ITCommonAddressData['key_activities'])

and thought the getSpecification-magic registers for the right 
Interface, but maybe I missunderstood the test. Registering an adapter 
by hand for zope.schema.interfaces.IList works.

..Carsten

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Automatic schema field sanitation?

2008-12-02 Thread Carsten Senger
Hi Dennis,

Dennis Noordsij schrieb:

 I would like to define a custom type inheriting from
 zope.schema.TextLine, which in addition to having a built-in constraint
 method also sanitizes the input.
 
 For example suppose you need to store codes of the kind: 3 letters,
 space, 3 numbers.
 
 The constraint uses a regexp, and this works fine.
 
 However it would be nice if I could also automatically capitalize the
 letters, such that abc 123 is stored as ABC 123 which is the
 presentation that should be used everywhere. Being able to do this
 automatically, just like the validation, would completely remove the
 need to remember to sanitize on input/output throughout the rest of the
 system.
 
 What would be the best way to implement this, ideally without needing to
 modify any of the standard zope.interface/zope.schema code?

IIRC invariants can change the passed data even though they are used 
nearly exclusive for cross field validation.

..Carsten

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users