python - How do I add form-level validation to a Flatland Form class? -
i have flatland form proxy website looks this:
class dosomethingform(form): '''do action account credentials''' username = string.using(default='', validators=[present(), usernameformat()]) password = string.using(default='', validators=[present(), passwordformat()]) action = string.using(default='', validators=[present(), actionformat()]) if of parameters empty, want validation error given elements empty. if non-empty , meet other requirements, next step ask other service if credentials valid. if invalid, want turn validation error.
this looks lot flatland's container-level validation, runs validation on contained elements first. tried this:
class dosomethingform(form): '''do action account credentials''' account = dict.of( username = string.named('username').using(default='', validators=[present(), usernameformat()]) password = string.named('password').using(default='', validators=[present(), passwordformat()]) ).using(validators=[checkcredentials()]) action = string.using(default='', validators=[present(), actionformat()]) this looks work, form looking elements named account_username , account_password, isn't quite interface hoping for.
i see couple of solutions:
- i attach
checkcredentialsvalidatordosomethingform. but, don't see way in documentation. - i attach
checkcredentialsvalidatorusername, can access siblingpassword. however, don't want bother other server if username , password in bad format. i'd have run validations onusername,passwordfirst, seems repeating myself. - i hack verson of
dictdoesn't namespacing
is there right way add form-level validators in flatland?
after reading bit of docs assume can your_form.validate().
the form class inherits dict class way can validation identical how container-level validation works.
disclaimer: until question i've never heard of "flatland" can off here.
Comments
Post a Comment