[ckan-dev] Modifying user's properties with code
David Read
david.read at okfn.org
Mon Sep 12 10:22:43 UTC 2011
On 11 September 2011 01:02, Rustam Mehmandarov <minspamboks at gmail.com> wrote:
> Hi again,
>
> While working on this code, I found a possible bug in CKAN when I
> tried deleting users using "paster --plugin=ckan user delete" command.
>
> To reproduce the bug do the following:
>
> 1. Create a user with an ID (which in my case was a user's full name)
> that contains non-unicode caracters like Norwegian "æ", "ø", or "å".
>
> 2. Make sure that you can see something like the example below:
> (pyenv) rm at mycomputer:$ paster --plugin=ckan user
> Users:
> name=Rustæm
>
> 3. Then try deleting the user with following command:
> (pyenv) rm at mycomputer:$ paster --plugin=ckan user delete "Rustæm"
>
> You should now get a python encoding error. I know that this is quite
> rare case, but in our case it caused some trouble. Could you guys have
> a look at this bug?
Rustam,
Many thanks for this bug report. Although the web interface and API
work well with unicode, the command-line tools for admins have not
been tested for this. I've raised a ticket for this and will make sure
this works soon: http://trac.ckan.org/ticket/1328
Cheers,
David
>
> CKAN ver. 1.3.3.
>
> Thanks a lot,
> Rustam
>
>
> On 5 September 2011 11:16, 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
>>
>
> _______________________________________________
> 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