using the quickstart authentication

8 views
Skip to first unread message

adam

unread,
Nov 20, 2009, 6:54:04 AM11/20/09
to TurboGears
Hello,

Within my app i allow a user to change their details. When i try and
do this

try:
username = request.identity['repoze.who.userid']
users = DBSession.query(User).filter_by
(user_name=session.get('old_username', None)).one()
users.user_name = str(cgi.escape(kw['username']))
users.display_name = str(cgi.escape(kw['display']))
users.email_address = str(cgi.escape(kw['email']))
flash(_('User updated'), 'info')
except:
flash(_('User not added'), 'error')
redirect('/settings/edit_user

everything works fine if i am updating the display name but when i
update the username or the email address nothing happen. The except
section doesnt kick in. The page is just redirected to /settings

What have i misses. I am using the quick start authentication method.

Thanks for any help

Adam

Christoph Zwerschke

unread,
Nov 20, 2009, 7:33:51 AM11/20/09
to turbo...@googlegroups.com
adam schrieb:
> What have i misses. I am using the quick start authentication method.

You're missing a DBSession.flush().

-- Christoph

adam

unread,
Nov 20, 2009, 7:37:03 AM11/20/09
to TurboGears
That still won't update the fields at all. Just the redirect.

Christoph Zwerschke

unread,
Nov 20, 2009, 8:05:29 AM11/20/09
to turbo...@googlegroups.com
adam schrieb:
> That still won't update the fields at all. Just the redirect.

You wrote that the exception does not take place, but in the code you
pasted, the redirect happens in the except clause?

Btw, instead of str(cgi.escape(...)) you should use the TurboGears
validate decorator on your parameters.

-- Christoph

adam

unread,
Nov 20, 2009, 8:35:23 AM11/20/09
to TurboGears
The redirect in the except is no happening its one else where that is
used if the update has occured.

What do you mean by TurboGears validate decorator on your parameters,
i am new to tg2 and have yet to explore everything.

Christoph Zwerschke

unread,
Nov 20, 2009, 9:17:34 AM11/20/09
to turbo...@googlegroups.com
adam schrieb:
> The redirect in the except is no happening its one else where that is
> used if the update has occured.

So you're seeing the flash message "User updated" and you have added the
DBSession.flush()? It should work then. Check if you're really picking
the right juser object with old_username. You can always add print, log
and assert statements, or add them to the flash message, to make such
things sure, or even use a debugger. If you still have problems, you
will need to paste your complete example.

http://turbogears.org/2.1/docs/main/Validation.html

> What do you mean by TurboGears validate decorator on your parameters,
> i am new to tg2 and have yet to explore everything.

http://turbogears.org/2.1/docs/main/Validation.html

-- Christoph

adam

unread,
Nov 23, 2009, 7:35:54 AM11/23/09
to TurboGears
ok i am trying to add in the validation but i am a little confused as
i am not using form widgets. So i am trying something like

@validate(validators={"kw['group']":validators.Int()})
def groupsession(self,**kw):
group_id =kw['group']
print "wanker"
print group_id


but i am getting the error NameError: name 'validate' is not defined
and i am importing like from formencode import validators. So i can
tell if i am doing this right. Any help?

Diez B. Roggisch

unread,
Nov 23, 2009, 7:43:40 AM11/23/09
to turbo...@googlegroups.com
On Monday 23 November 2009 13:35:54 adam wrote:
> ok i am trying to add in the validation but i am a little confused as
> i am not using form widgets. So i am trying something like
>
> @validate(validators={"kw['group']":validators.Int()})
> def groupsession(self,**kw):
> group_id =kw['group']
> print "wanker"
> print group_id
>
>
> but i am getting the error NameError: name 'validate' is not defined
> and i am importing like from formencode import validators. So i can
> tell if i am doing this right. Any help?


from tg import validate

Should be in a quickstarted project.

Diez

Christoph Zwerschke

unread,
Nov 23, 2009, 8:25:32 AM11/23/09
to turbo...@googlegroups.com
Diez B. Roggisch wrote:
> adam wrote:
>> ok i am trying to add in the validation but i am a little confused as
>> i am not using form widgets. So i am trying something like
>>
>> @validate(validators={"kw['group']":validators.Int()})
>> def groupsession(self,**kw):
>> ...
>>
>> but i am getting the error NameError: name 'validate' is not defined
>> and i am importing like from formencode import validators. So i can
>> tell if i am doing this right. Any help?
>
> from tg import validate
>
> Should be in a quickstarted project.

Also, you're using kw in the decorator where it's not defined. Just put
'group' there. You can also use a Form/Schema.

-- Christoph
Reply all
Reply to author
Forward
0 new messages