I'm working on using TurboGears 2.3 and validating forms with formencode and doing some guidance I have a form that contains 2 different items are almost identical, but with some difference when I submit my form, then I want to validate 2 things.
>- Some basic data
- Certain data for a specific object
Yes my schema:
class basicQuestionSchema (schema): questionType = validators.OneOf ([ 'selectQuestion', 'yesNoQuestion', 'amountQuestion']) Allow_extra_fields = true class_or_yes_no_question_Schema (schema): questionText = validators.NotEmpty () product_id_radio = object_exist_by_id (unit = product, not_empty = true) allow_extra_fields = true class selectQuestionSchema (schema): questionText = validators.NotEmpty () product_ids = validators NotEmpty () allow_extra_fields = true
and here's how my controller:
@expose () @validate (Authenticators = basicQuestionSchema (), error_handler = questionEditError) Def saveQuestion (self, ** kw): type = K.V. [ 'Prsnprkar'] if type == 'selection question': sel f.save_select_question (** kw) and: self.save_amount_or_yes_no_question (** kw) @validate (Authenticators = selectQuestionSchema (), error_handler = questionEditError) def save_select_question (self , ** kw): ... do stuff ... @ valid (Authenticators = amount_or_yes_no_question_Schema (), error_handler = questionEditError) def Save_amount_or_yes_no_question (self, ** kw): ... other stuff ...
I wanted to have been recognized twice, it does not work with different schemas because only the first validity is valid, and the other (Probably not overlooked)
So, what am I doing wrong?
Thanks for the help
@validate
request Is part of the flow, so the controller is not executing it manually (this is not a standard dragon decorator), all TG2 decorators actually use only one hook to register tg.hooks
Flow is bound to request).
If you are trying to achieve should be done during the validation phase, as the plain object methods after verification save_select_question
and save_amount_or_yes_no_question < / Code> can call.
A work example of conditional verification.
Comments
Post a Comment