[ckan-dev] Disqus comments plugin SSO enhancement
Koebrick, Andrew (MNIT)
andrew.koebrick at state.mn.us
Mon Nov 17 21:42:02 UTC 2014
Adrià,
Thanks for the pointers; I am now able to access the user data. One small change from the code you provided was needed (in case anyone else tries this):
I had to use c.user in the get_action:
user_dict = p.toolkit.get_action('user_show')({'keep_email': True}, {'id': c.user})
As opposed to using c.name as you suggested:
user_dict = p.toolkit.get_action('user_show')({'keep_email': True}, {'id': c.name})
Now on to see implementing the Single Sign On...
Andrew
-----Original Message-----
From: ckan-dev [mailto:ckan-dev-bounces at lists.okfn.org] On Behalf Of Adrià Mercader
Sent: Friday, November 14, 2014 5:03 AM
To: CKAN Development Discussions
Subject: Re: [ckan-dev] Disqus comments plugin SSO enhancement
Hi Andrew,
To access properties in c you need to access them like `c.user`. This gives you the user name.
Passing data in c to the templates is not the recommended method any more. Passing variables as in here is recommended:
https://github.com/ckan/ckanext-disqus/blob/master/ckanext/disqus/plugin.py#L92:L96
These can be later accessed from the templates directly:
https://github.com/ckan/ckanext-disqus/blob/master/ckanext/disqus/templates/disqus_comments.html#L5:L6
In your case you need to call `user_show` to get all the extra details you need, something like this should get you started:
user_dict = p.toolkit.get_action('user_show')({'keep_email':
True}, {'id': c.name})
data = {
...
'user_id: user_dict['id'],
'user_name': user_dict['name'],
'user_email': user_dict['email'],
}
return p.toolkit.render_snippet('disqus_comments.html', data)
Hope this helps,
Adrià
On 13 November 2014 19:02, Koebrick, Andrew (MNIT) <andrew.koebrick at state.mn.us> wrote:
> I am trying to create a fork of the ckanext-disqus extension that
> makes use of the Single Sign On (SSO) which Disqus offers. Rather
> than have users have to sign into the Disqus service, local user data is sent to Disqus.
> For more info see:
> https://help.disqus.com/customer/portal/articles/236206-integrating-si
> ngle-sign-on
>
>
>
> However, I have having a difficult time accessing the ckan user model
> from the extension. Could somebody with a better knowledge of CKAN
> and python give me a pointer or two? I seem to be unable to access to context object.
> I have been trying things like the below with no luck;
>
>
>
> def disqus_comments(cls):
> #Original code
>
> ''' Adds Disqus Comments to the page.'''
> #Original code
>
> # we need to create an identifier #Original code
>
> c = p.toolkit.c
> #Original code
>
>
>
> user_name = c['user']
> #My addition … It fails.
>
> user_name = context['user']
> #Another try. as seen in the extension tutorial… It fails.
>
>
>
>
>
> I need to access to user’s name, email, and Id.
>
>
>
> Thanks in advance for any pointers anyone can provide. If I get SSO
> hooked up in my fork, I will happily share my code back to the main extension.
>
>
>
> Andrew Koebrick
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>
_______________________________________________
ckan-dev mailing list
ckan-dev at lists.okfn.org
https://lists.okfn.org/mailman/listinfo/ckan-dev
Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
More information about the ckan-dev
mailing list