On Saturday 26 May 2007 07:13:50 aspineux wrote:
>
> @turbogears.expose()
> @validate(form=user_form)
> @error_handler(index)
> def user_create(self, user_name, password, password2, tg_value=None,
> tg_state=None, **kwargs):
>     if password1!=password2:
>         # YES I know and I can use FieldsMatch for that :-)
>         raise turbogears.validators.Invalid('Passwords dont match',
> tg_value, tg_state,
>
> error_dict={'password2': 'Password dont match' })
>
>     newuser=model.User(user_name=user_name, password=password)
>     session.save(newuser)
>     try:
>         session.flush()
>     except:
>         raise turbogears.validators.Invalid('Username already in use',
> tg_value, tg_state,
>
> error_dict={'user_name: 'choose another username' })
>
>     user_id=newuser.user_id
>     turbogears.flash("User successfuly added, user_id=!" % user_id)
>
>     raise turbogears.redirect('show_user', dict(user_id=user_id))
>
> Will this be possible in a future release of Turbogears ?

I'd rather use a custom validator.  The logic is clearer, you write less 
repetitive code, you reuse more components, no changes to TG are required, 
you can have all that *now*.

Also, your changes imply in changing how TG is working with FormEncode.

What I see is that this would bring more harm than good and would add extra 
code that needed to be maintained in TG.

On the other hand, nothing prevents you from coding that: you can create new 
decorators and make them do what you want.  There are three dicts that you 
can use  (that I remember right now, maybe there's something more): you can 
get your submited data with a **kwargs dictionary, you can check (/set?) 
validation errors on tg_errors and you can send back values on a dict of your 
own to be redisplayed on the form.

So, even though there's no written code on TG core that does what you want, 
you can get it to work like that in, lets say, one weekend. 


-- 
Jorge Godoy      <[EMAIL PROTECTED]>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to