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:

  1. i attach checkcredentials validator dosomethingform. but, don't see way in documentation.
  2. i attach checkcredentials validator username, can access sibling password. however, don't want bother other server if username , password in bad format. i'd have run validations on username , password first, seems repeating myself.
  3. i hack verson of dict doesn'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

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -