[ckan-dev] Disqus comments plugin SSO enhancement

Adrià Mercader adria.mercader at okfn.org
Tue Nov 18 08:24:53 UTC 2014


Hi Andrew,

You are absolutely right, my mistake.

Good luck!

Adrià
On 17 Nov 2014 21:42, "Koebrick, Andrew (MNIT)" <andrew.koebrick at state.mn.us>
wrote:

> 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
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20141118/02e9e3b0/attachment-0003.html>


More information about the ckan-dev mailing list