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

David Read david.read at okfn.org
Mon Sep 12 15:53:02 UTC 2011


By the way, if Rustam or anyone else can try to fix little bugs like
this, then please do - we are trying to be as open and collaborative
as possible.

I've put easy instructions for submitting a patch here:
http://wiki.ckan.net/Submitting_a_code_patch

David

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