Adam, thanks for your answer.
I've tried what you explained, and it worked. But I still have doubts about the proper way to do this.

My edit method looks like:

    @expose(template="xxxxx")
    def edit(self, userId):
        user = UserServices.getById(userId)
        return dict(user = user)

The template is posting to a save method which looks like:
   @expose()
    @error_handler(form_error)
    @validate(validators={"email": validators.Email(not_empty=True)})  
    def save(self, userName, email, displayName, password, passwordConfirm, upload_file = None, userId = None):
        msg = UserServices.saveUser(userName, email, displayName, password, passwordConfirm, upload_file, groups, userId)
        turbogears.flash(msg)
        turbogears.redirect('/users/list')

and the form_error method looks like:

    def form_error(self, userName, email, displayName, password, passwordConfirm, upload_file = None, userId = None, tg_errors=None):
        if tg_errors:
            message = [str(item) for item in tg_errors.values()]
            message = ', '.join(message)
            turbogears.flash(message)
            if userId:
                turbogears.redirect('/users/edit/' + userId)
            else:
                turbogears.redirect('/users/add')

The thing is that if while editing I changed the username, as I am being redirected to the initial edit, the user has to place that changes again.

I guess there is a simpler way to do this....

On 10/3/06, Adam Jones <[EMAIL PROTECTED]> wrote:

Have you tried putting @error_handler on the validating controller?
Here is an example:

from turbogears import error_handler

def myform(self, **stuff):
    form code here

@error_handler(myform)
@validate(form=my_input_form)
def myformvalidator(self, **stuff):
    handle result after validation

Any validation errors result in the user being pushed to the controller
listed as an error_handler. You can get more info here:

http://docs.turbogears.org/1.0/ErrorHandling

-Adam




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to