[ckan-dev] Modifying user's properties with code
David Read
david.read at okfn.org
Mon Sep 5 09:16:10 UTC 2011
On 3 September 2011 22:53, Rustam Mehmandarov <minspamboks at gmail.com> wrote:
> Hi all,
>
> I have a code that creates a user if it does not exists:
>
> if user is None:
> user = User(openid=user_id,
> name=data['name'],
> fullname=data['name'],
> email=data['mail'])
> Session.add(user)
> Session.commit()
> Session.remove()
>
> But now, I also need some code that is able to update (for example)
> the user's name every time I log in (the data is sent from another
> system that does the authentication for CKAN). Is there some kind of
> update user function in Session? Then I can do something like:
>
> user = User(openid=user_id,
> name=data['name'],
> fullname=data['name'],
> email=data['mail'])
> if user is None:
> Session.add(user)
> else:
> Session.UPDATE(user)
> Session.commit()
> Session.remove()
>
> Any kind of help is greatly appreciated. :)
Hi Rustam,
The first line of this is probably the key you need:
user = model.Session.query(model.User).filter_by(openid=user_id).first()
if user:
user.name = data['name']
else:
user = User(openid=user_id,
name=data['name'],
fullname=data['name'],
email=data['mail'])
Session.add(user)
Session.commit()
Session.remove()
David
>
> Thanks!
> Rustam
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
>
More information about the ckan-dev
mailing list