This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', |