Get data edited via custom pipeline to view

110 views
Skip to first unread message

Varghese Chacko

unread,
Mar 29, 2016, 1:20:12 PM3/29/16
to Django Social Auth
I have created a custom pipeline to have PSA create a user profile, with data from facebook. My Auth pipeline is

SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.user.get_username',
    'social.pipeline.user.create_user',
    'myapp.lib.social.save_profile',  # <------ My pipeline
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
)


The pipeline function is

def save_profile(backend, user, response, *args, **kwargs):

    if backend.name == 'facebook':
        profile, created = UserProfile.objects.get_or_create(user=user)
        profile.facebook_id = response.get('id')
        profile.email = response.get('email', '')
        profile.school = response.get('school', '')
        profile.gender = response.get('gender')
        profile.profile_picture = response.get('picture', {}).get('data', {}).get('url', {})
        profile.save()

        data = serializers.serialize('python', [profile])


        print "\n\nIn save profile\n", datetime.datetime.now(), data #<----- printing debug info



My view is 

@psa('social:complete')
def register_by_access_token(request, backend):
    token = request.GET.get('access_token')
    user = request.backend.do_auth(request.GET.get('access_token'))


    if user:
        login(request, user)
        profile = UserProfile(user=user)
        data = serializers.serialize('python', [profile])

        print "\n\nIn register by access_token\n",datetime.datetime.now(), data # <---------- debug info

        return JsonResponse({'status': 'Success', 'status_message': 'You have successfully loged in'})
    else:
        return JsonResponse({'status': 'Error', 'status_message': 'Error while login'})



On shell I get

In save profile
2016-03-29 17:06:14.189348 [OrderedDict([(u'model', u'roomring.userprofile'), (u'pk', 5), (u'fields', OrderedDict([('created_on', datetime.datetime(2016, 3, 29, 13, 37, 41, 577562, tzinfo=<UTC>)), ('updated_on', datetime.datetime(2016, 3, 29, 17, 6, 14, 167378, tzinfo=<UTC>)), ('is_active', 1), ('is_deleted', 0), ('user', 5), ('facebook_id', u'3242432432432432432'), ('facebook_mutual_friends', u'{}'), ('email', u'v...@gmail.com'), ('gender', 0), ('school', u''), ('profession', u''), ('about_me', u''), ('profile_picture', u'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xla1/v/t1.0-1/p50x50/1252397fghgfh9_10153592353686902_396698214344651002_n.jpg?oh=a5ec4c5e549721tyee9a5b7fa5f29eb9a7&oe=578gfh2621A&__gda__=1469071880_5b3d1b1f40fdghfc7041b051956f53d03b6e')]))])]


In register by access_token
2016-03-29 17:06:14.216842 [OrderedDict([(u'model', u'roomring.userprofile'), (u'pk', None), (u'fields', OrderedDict([('created_on', None), ('updated_on', None), ('is_active', 1), ('is_deleted', 0), ('user', 5), ('facebook_id', u''), ('facebook_mutual_friends', '{}'), ('email', u''), ('gender', 0), ('school', u''), ('profession', u''), ('about_me', u''),  ('profile_picture', u''), ]))])]
[29/Mar/2016 17:06:14] "GET /api/web_app_login/facebook/?access_token=CAAFg7CKJ2nABAF2xyycY82NitxeCc4alSKaRdQ15t04l50hlXxZBKR9pCj25TL1S3liMDOwEGUhxAagDT7vWdB8KLEKUTDPyuMjhoek7OK2yRpXzP49Mh6syhzJuZB7yc7ZBJkxY9ZB9cOznPl3wZDZD HTTP/1.1" 200 73


In the pipeline everything is perfect, but when I fetch the same model (profile) in the View, its empty. I wish to get the values saved in the pipeline in the view to return as JSON.

Please help



















Varghese Chacko

unread,
Mar 29, 2016, 2:51:21 PM3/29/16
to Django Social Auth
BTW, it will be great if I can get values for is_new & is_new_association in register_by_access_token

Matías Aguirre

unread,
Mar 29, 2016, 3:44:16 PM3/29/16
to DSA Group
Hi,

First, python-social-auth questions should be sent to the
python-social-auth mailing list
(https://groups.google.com/forum/#!forum/python-social-auth), this one
is deprecated.

I think that in your view, you aren't actually getting the user
profile for that user, you should be doing
"User.objects.get(user=user)" instead.

About the "is_new", you can get it by doing "user.is_new",
"is_new_association" is not accessible outside the pipeline, but you
can store anything in the request session if that helps.


On Tue, Mar 29, 2016 at 3:51 PM, Varghese Chacko <vargh...@gmail.com> wrote:
> BTW, it will be great if I can get values for is_new & is_new_association in
> register_by_access_token
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django Social Auth" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-social-a...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Matías Aguirre
http://matiasaguirre.net

Varghese Chacko

unread,
Mar 29, 2016, 11:42:15 PM3/29/16
to Django Social Auth
 Thank You, it worked.

Reply all
Reply to author
Forward
0 new messages