Skip to content

Instantly share code, notes, and snippets.

@cansadadeserfeliz
cansadadeserfeliz / pipeline.py
Last active December 10, 2018 21:03
Django: python-social-auth configuration and pipeline to get users email, full name and save avatar for Facebook, Twitter, LinkedIn and Google http://blog.vero4ka.info/blog/2015/03/02/django-python-social-auth-configuration-and-pipeline-to-get-users-information/
def update_user_social_data(strategy, *args, **kwargs):
"""Set the name and avatar for a user only if is new.
"""
print 'update_user_social_data ::', strategy
if not kwargs['is_new']:
return
full_name = ''
backend = kwargs['backend']
@yprez
yprez / fields.py
Last active February 19, 2023 12:08
Django rest framework - Base64 image field
import base64
from django.core.files.base import ContentFile
from rest_framework import serializers
class Base64ImageField(serializers.ImageField):
def from_native(self, data):
if isinstance(data, basestring) and data.startswith('data:image'):
# base64 encoded image - decode
@karmadonov
karmadonov / base64.py
Last active January 29, 2018 15:46
Upload base64 file from POST request to Django form
import base64
import cStringIO
from django.core.files.uploadedfile import InMemoryUploadedFile
# ...
if request.POST.get('file') and request.POST.get('name'):
file = cStringIO.StringIO(base64.b64decode(request.POST['file']))
image = InMemoryUploadedFile(file,
field_name='file',