当前位置: 首页>>代码示例>>Python>>正文


Python Avatar.save方法代码示例

本文整理汇总了Python中avatar.models.Avatar.save方法的典型用法代码示例。如果您正苦于以下问题:Python Avatar.save方法的具体用法?Python Avatar.save怎么用?Python Avatar.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在avatar.models.Avatar的用法示例。


在下文中一共展示了Avatar.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def add(request, extra_context=None, next_override=None, upload_form=UploadAvatarForm, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    upload_avatar_form = upload_form(request.POST or None, request.FILES or None, user=request.user)
    if request.method == "POST" and "avatar" in request.FILES:
        if upload_avatar_form.is_valid():
            avatar = Avatar(user=request.user, primary=True)
            image_file = request.FILES["avatar"]
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            messages.add_message(request, messages.INFO, _("Successfully uploaded a new avatar"))
            avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
            return HttpResponseRedirect(next_override or _get_next(request))
    return render_to_response(
        "avatar/add.html",
        extra_context,
        context_instance=RequestContext(
            request,
            {
                "avatar": avatar,
                "avatars": avatars,
                "upload_avatar_form": upload_avatar_form,
                "next": next_override or _get_next(request),
            },
        ),
    )
开发者ID:saebyn,项目名称:django-avatar,代码行数:29,代码来源:views.py

示例2: add

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def add(request, extra_context=None, next_override=None,
        upload_form=UploadAvatarForm, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    upload_avatar_form = upload_form(request.POST or None,
        request.FILES or None, user=request.user)
    if request.method == "POST" and 'avatar' in request.FILES:
        if upload_avatar_form.is_valid():
            avatar = Avatar(
                user = request.user,
                primary = True,
            )
            image_file = request.FILES['avatar']
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            request.user.message_set.create(
                message=_("Successfully uploaded a new avatar."))
            avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
            return HttpResponseRedirect(next_override or _get_next(request))
    return render_to_response(
            'avatar/add.html',
            extra_context,
            context_instance = RequestContext(
                request,
                { 'avatar': avatar, 
                  'avatars': avatars, 
                  'upload_avatar_form': upload_avatar_form,
                  'next': next_override or _get_next(request), }
            )
        )
开发者ID:ASKBOT,项目名称:django-avatar,代码行数:33,代码来源:views.py

示例3: add_avatar_for_user

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def add_avatar_for_user(request, for_user=None, extra_context=None,
        next_override=None,
        upload_form=UploadAvatarForm, *args, **kwargs):
    target_user = get_object_or_404(User, username=for_user, is_active=True)
    if not AVATAR_ADMIN_TEST(request, target_user):
        raise PermissionDenied
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(target_user)
    upload_avatar_form = upload_form(request.POST or None,
        request.FILES or None, user=target_user)
    if request.method == "POST" and 'avatar' in request.FILES:
        if upload_avatar_form.is_valid():
            avatar = Avatar(
                user = target_user,
                primary = True,
            )
            image_file = request.FILES['avatar']
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            messages.add_message(request, messages.INFO, _("Successfully uploaded a new avatar"))
            avatar_updated.send(sender=Avatar, user=target_user, avatar=avatar)
            return redirect(next_override or _get_next(request))
    context = {
        'avatar': avatar,
        'avatars': avatars,
        'target_user': target_user,
        'upload_avatar_form': upload_avatar_form,
        'next': next_override or _get_next(request),
    }
    context.update(extra_context)
    return render(request, 'avatar/add_for_user.html', context)
开发者ID:numegil,项目名称:django-avatar,代码行数:34,代码来源:views.py

示例4: get_user_avatar

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def get_user_avatar(backend, details, response, social_user, uid,\
                    user, *args, **kwargs):
    url = None
    if backend.__class__ == FacebookBackend:
        url = "http://graph.facebook.com/%s/picture?type=large" % response['id']

    print response.keys()
    if url:
        print url
        avtr = Avatar(
                user = user,
                primary = True,
            )
        image_request = requests.get(url)
        print image_request.headers
        content_type=image_request.headers['content-type']
        print content_type
        filename = user.username
        if content_type == 'image/jpeg':
            filename = "%s.jpg" % user.username
        if content_type == 'image/png':
            filename = "%s.png" % user.username
        image_file = SimpleUploadedFile(
            filename,
            image_request.content,
            content_type=content_type
        )
        print image_file.__dict__
        avtr.avatar.save(image_file.name, image_file)
        avtr.save()
开发者ID:PoorlyWritten,项目名称:togoweb,代码行数:32,代码来源:pipelines.py

示例5: user_signed_up_

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def user_signed_up_(request, user, sociallogin=None, **kwargs):
	'''
	When a social account is created successfully and this signal is received,
	django-allauth passes in the sociallogin param, giving access to metadata on the remote account, e.g.:

	sociallogin.account.provider  # e.g. 'twitter'
	sociallogin.account.get_avatar_url()
	sociallogin.account.get_profile_url()
	sociallogin.account.extra_data['screen_name']

	See the socialaccount_socialaccount table for more in the 'extra_data' field.
	'''

	if sociallogin:
	# Extract first / last names from social nets and store on Profile record
		if sociallogin.account.provider == 'facebook':
			user.profile.first_name = sociallogin.account.extra_data['first_name']
			user.profile.last_name = sociallogin.account.extra_data['last_name']

		if sociallogin.account.provider == 'google':
			user.profile.first_name = sociallogin.account.extra_data['given_name']
			user.profile.last_name = sociallogin.account.extra_data['family_name']
	
		user.profile.save()
	
		mage_avatar = user.profile.download_avatar(sociallogin.account.get_avatar_url())
		avatar = Avatar(user=user,primary=True, avatar=image_avatar)
		avatar.save()
开发者ID:jomauricio,项目名称:abgthe,代码行数:30,代码来源:handlers.py

示例6: add

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def add(request, extra_context=None, next_override=None,
        upload_form=UploadAvatarForm, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    upload_avatar_form = upload_form(request.POST or None,
        request.FILES or None, user=request.user)
    if request.method == "POST" and 'avatar' in request.FILES:
        if upload_avatar_form.is_valid():
            avatar = Avatar(
                emailuser = request.user.username,
                primary = True,
            )
            image_file = request.FILES['avatar']
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            messages.success(request, _("Successfully uploaded a new avatar."))
            avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
            return HttpResponseRedirect(next_override or _get_next(request))
        else:
            messages.error(request, upload_avatar_form.errors['avatar'])

        return HttpResponseRedirect(_get_next(request))
    else:
        # Only allow post request to change avatar.
        raise Http404
开发者ID:beride,项目名称:seahub,代码行数:28,代码来源:views.py

示例7: add

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def add(request, extra_context=None, next_override=None,
        upload_form=UploadAvatarForm, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    upload_avatar_form = upload_form(request.POST or None,
        request.FILES or None, user=request.user)
    if request.method == "POST" and 'avatar' in request.FILES:
        if upload_avatar_form.is_valid():
            avatar = Avatar(
                user = request.user,
                primary = True,
            )
            image_file = request.FILES['avatar']
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            request.user.message_set.create(
                message=_("Successfully uploaded a new avatar."))
            if notification:
                _notification_updated(request, avatar)
            return HttpResponseRedirect(next_override or _get_next(request))
    data = { 
        'avatar': avatar, 
        'avatars': avatars, 
        'upload_avatar_form': upload_avatar_form,
        'next': next_override or _get_next(request),
        'view_user': request.user,
        'page_class': 'avatar-page',
    }
    if extra_context:
        data.update(extra_context)

    return render_into_skin('avatar/add.html', data, request)
开发者ID:Arpaso,项目名称:askbot-devel,代码行数:35,代码来源:avatar_views.py

示例8: update_from_facebook

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def update_from_facebook(user, facebook_obj):
    """docstring for update_from_facebook"""
    profile = getattr(facebook_obj, 'profile', None)
    if not profile:
        facebook_obj.profile = facebook_obj.graph.get_object("me")
        profile = facebook_obj.profile
    # update django user information
    user.email = profile['email']
    user.first_name = profile['first_name']
    user.last_name = profile['last_name']
    user.save()
    # update pinax profile information
    pinax_profile = Profile.objects.get(user=user)
    pinax_profile.name = profile['name']
    pinax_profile.save()
    # populate email address in emailconfirmation app
    email = EmailAddress.objects.create(user=user, email=profile['email'], verified=True)
    email.set_as_primary(conditional=True)
    email.save()
    # save profile picture
    picture = urllib2.urlopen("http://graph.facebook.com/%s/picture" % facebook_obj.uid)
    picture_file = ContentFile(picture.read())
    avatar = Avatar(
        user = user,
        primary = True,
    )
    avatar.avatar.save('%s.jpg' % facebook_obj.uid, picture_file)
    avatar.save()
开发者ID:bsheng,项目名称:GrooveCal,代码行数:30,代码来源:forms.py

示例9: add

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def add(request, extra_context=None, next_override=None,
        upload_form=UploadAvatarForm, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    upload_avatar_form = upload_form(request.POST or None,
        request.FILES or None, user=request.user)
    if request.method == "POST" and 'avatar' in request.FILES:
        if upload_avatar_form.is_valid():
            avatar = Avatar(
                user = request.user,
                primary = True,
            )
            image_file = request.FILES['avatar']
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            updated = True
            request.user.message_set.create(
                message=_(u"Zdjęcie zostało pomyślnie dodane."))
            if notification:
                _notification_updated(request, avatar)
    return render_to_response(
            'avatar/add.html',
            extra_context,
            context_instance = RequestContext(
                request,
                { 'avatar': avatar, 
                  'avatars': avatars, 
                  'upload_avatar_form': upload_avatar_form,
                  'next': next_override or _get_next(request), }
            )
        )
开发者ID:lukaszsliwa,项目名称:Mapy,代码行数:34,代码来源:views.py

示例10: upload

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def upload(request, user_id=None):
    user = get_object_or_404(User, pk=user_id)
    if request.method == 'POST':
        if 'avatar' in request.FILES:
            form = UploadAvatarForm(
                            request.POST,
                            request.FILES,
                            user=user)
            if form.is_valid():
                avatar = Avatar(user=user, primary=True)
                image_file = request.FILES['avatar']
                avatar.avatar.save(image_file.name, image_file)
                avatar.save()
                sizes = avatar_settings.AVATAR_AUTO_GENERATE_SIZES
                for size in sizes:
                    avatar.create_thumbnail(size)
                avatar_updated.send(sender=Avatar, user=user, avatar=avatar)
                user.avatar_type = 'a'
                user.clear_avatar_urls()
                user.save()
                message = _('Avatar uploaded and set as primary')
            else:
                errors = get_error_list(form)
                message = ', '.join(map(lambda v: force_str(v), errors))
        else:
            message = _('Please choose file to upload')

        request.session['askbot_avatar_status_message'] = message

    return redirect_to_show_list(user_id)
开发者ID:diegomatar,项目名称:askbot-devel,代码行数:32,代码来源:avatar_views.py

示例11: upload_avatar_js

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def upload_avatar_js(request):
    '''
    Upload avatar image
    '''
    response = {}
    status = 405
    if request.is_ajax() and request.method == 'POST':
        from avatar.models import Avatar
        from avatar import views as avatarviews
        from avatar.forms import UploadAvatarForm
        from avatar.signals import avatar_updated
        avatar, avatars = avatarviews._get_avatars(request.user)
        upload_avatar_form = UploadAvatarForm(None, request.FILES, user=request.user)
        if upload_avatar_form.is_valid():
            avatar = Avatar(
                user = request.user,
                primary = True,
            )
            image_file = request.FILES['avatar']
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
            response['avatar'] = accountutil.get_user_avatar_url(request.user)
            status = 200
    return HttpResponse(
        simplejson.dumps(response),
        content_type = 'application/json; charset=utf8',
        status=status
    )
开发者ID:fcardinaux,项目名称:fiduswriter,代码行数:31,代码来源:views.py

示例12: avatar_crop

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def avatar_crop(request, id=None):
    """
    Avatar management, creates a new avatar and makes it default
    """
    if id:
        avatar = get_object_or_404(Avatar, id=id, user=request.user)
    else:
        avatar = get_object_or_404(Avatar, user=request.user, primary=True)

    if (avatar.avatar.width<=avatar.avatar.height):
        result = "width"
    else:
        result = "height"

    if not request.method == "POST":
        form = AvatarCropForm()
    else:
        try:
            orig = avatar.avatar.storage.open(avatar.avatar.name, 'rb').read()
            image = Image.open(StringIO(orig))
        except IOError:
            return
        form = AvatarCropForm(image, request.POST)

        if form.is_valid():
            top = int(form.cleaned_data.get('top'))
            left = int(form.cleaned_data.get('left'))
            right = int(form.cleaned_data.get('right'))
            bottom = int(form.cleaned_data.get('bottom'))

            box = [ left, top, right, bottom ]
            (w, h) = image.size
            if result=="width":
                box = map(lambda x: x*h/AVATAR_CROP_MAX_SIZE, box)
            else:
                box = map(lambda x: x*w/AVATAR_CROP_MAX_SIZE, box)

            image = image.crop(box)
            if image.mode != 'RGB':
                image = image.convert('RGB')

            thumb = StringIO()
            image.save(thumb, AVATAR_THUMB_FORMAT, quality=AVATAR_THUMB_QUALITY)
            thumb_file = ContentFile(thumb.getvalue())

            base_name, ext = os.path.splitext(avatar.avatar.name)
            thumb = avatar.avatar.storage.save("%s_cropped%s" % (base_name, ext), thumb_file)
            Avatar.objects.filter(id=avatar.id).update(primary=False)
            new_avatar = Avatar(user=request.user, primary=True, avatar=thumb)
            new_avatar.save()
            request.user.message_set.create(
                message=ugettext("Your new avatar has been saved successfully."))
            return HttpResponseRedirect(reverse("avatar_change"))

    return render_to_response("avatar_crop/crop.html", {
        'AVATAR_CROP_MAX_SIZE': AVATAR_CROP_MAX_SIZE,
        'dim': result,
        'avatar': avatar,
        'form': form
    }, context_instance=RequestContext(request))
开发者ID:Gidsy,项目名称:django-avatar-crop,代码行数:62,代码来源:views.py

示例13: add

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def add(request, extra_context=None, next_override=None,
        upload_form=UploadAvatarForm, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    upload_avatar_form = upload_form(request.POST or None,
                                     request.FILES or None,
                                     user=request.user)
    if request.method == "POST" and 'avatar' in request.FILES:
        if upload_avatar_form.is_valid():
            avatar = Avatar(user=request.user, primary=True)
            image_file = request.FILES['avatar']
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            # messages.success(request, _("Successfully uploaded a new avatar."))
            avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
            return redirect(next_override or _get_next(request))
    context = {
        'avatar': avatar,
        'avatars': avatars,
        'upload_avatar_form': upload_avatar_form,
        'next': next_override or _get_next(request),
    }
    context.update(extra_context)
    return render(request, 'avatar/add.html', context)
开发者ID:marchibbins,项目名称:bootstrap-tenants,代码行数:27,代码来源:views.py

示例14: add

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def add(request, extra_context=None, next_override=None, upload_form=UploadAvatarForm, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    upload_avatar_form = upload_form(request.POST or None, request.FILES or None, user=request.user)
    if request.method == "POST" and "avatar" in request.FILES:
        if upload_avatar_form.is_valid():
            avatar = Avatar(user=request.user, primary=True)
            image_file = request.FILES["avatar"]
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            request.user.message_set.create(message=_("Successfully uploaded a new avatar."))
            if notification:
                _notification_updated(request, avatar)
            return HttpResponseRedirect(next_override or _get_next(request))
    data = {
        "avatar": avatar,
        "avatars": avatars,
        "upload_avatar_form": upload_avatar_form,
        "next": next_override or _get_next(request),
        "view_user": request.user,
        "page_class": "avatar-page",
    }
    if extra_context:
        data.update(extra_context)

    return render(request, "avatar/add.html", data)
开发者ID:nordic-olha,项目名称:askbot-nordic,代码行数:29,代码来源:avatar_views.py

示例15: upload_avatar_js

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import save [as 别名]
def upload_avatar_js(request):
    '''
    Upload avatar image
    '''
    response = {}
    status = 405
    if request.is_ajax() and request.method == 'POST':

        avatar, avatars = avatarviews._get_avatars(request.user)
        upload_avatar_form = UploadAvatarForm(
            None,
            request.FILES,
            user=request.user
        )
        if upload_avatar_form.is_valid():
            avatar = Avatar(
                user=request.user,
                primary=True,
            )
            image_file = request.FILES['avatar']
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            avatar_updated.send(
                sender=Avatar,
                user=request.user,
                avatar=avatar
            )
            response['avatar'] = userutil.get_user_avatar_url(request.user)
            status = 200
    return JsonResponse(
        response,
        status=status
    )
开发者ID:OSCOSS,项目名称:fiduswriter,代码行数:35,代码来源:views.py


注:本文中的avatar.models.Avatar.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。