[ckan-dev] Modifying user's properties with code

Rustam Mehmandarov minspamboks at gmail.com
Mon Sep 5 18:03:04 UTC 2011


Thanks a lot, David! I just realized that too after digging deeper into the
code.
On Sep 5, 2011 11:16 AM, "David Read" <david.read at okfn.org> wrote:
> 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
>>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20110905/47f5c894/attachment-0001.html>


More information about the ckan-dev mailing list