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


Python Avatar.create_thumbnail方法代码示例

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


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

示例1: upload

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import create_thumbnail [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

示例2: process_request

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import create_thumbnail [as 别名]
    def process_request(self, request):
        # AuthenticationMiddleware is required so that request.user exists.
        if not hasattr(request, 'user'):
            raise ImproperlyConfigured(
                "The Django remote user auth middleware requires the"
                " authentication middleware to be installed.  Edit your"
                " MIDDLEWARE_CLASSES setting to insert"
                " 'django.contrib.auth.middleware.AuthenticationMiddleware'"
                " before the RemoteUserMiddleware class.")
        try:
            username = request.META[self.header]
        except KeyError:
            # If specified header doesn't exist then remove any existing
            # authenticated remote-user, or return (leaving request.user set to
            # AnonymousUser by the AuthenticationMiddleware).
            if self.force_logout_if_no_header and request.user.is_authenticated:
                self._remove_invalid_user(request)
            return
        # If the user is already authenticated and that user is the user we are
        # getting passed in the headers, then the correct user is already
        # persisted in the session and we don't need to continue.
        if request.user.is_authenticated:
            #if request.user.get_username() == self.clean_username(username, request):
            if request.user.get_username() == username[:username.find("@")]:
                return
            else:
                # An authenticated user is associated with the request, but
                # it does not match the authorized user in the header.
                self._remove_invalid_user(request)

        # We are seeing this user for the first time in this session, attempt
        # to authenticate the user.
        user = auth.authenticate(remote_user=username)
        if user:
            # User is valid.  Set request.user and persist user in the session
            # by logging the user in.
            request.user = user
            auth.login(request, user)
            if user.email != username:
                user.email = username
                user.email_isvalid = True
                user.first_name = request.META['HTTP_X_AUTH_GIVEN_NAME']
                user.last_name = request.META['HTTP_X_AUTH_FAMILY_NAME']
                user.real_name = user.first_name + ' ' + user.last_name
                user.save()

            # If there's no avatar directory for this user on disk, retrieve the avatar from google
            # and set as primary
            if not os.path.exists("/var/askbot-site/askbot/upfiles/avatars/" + username[:username.find("@")]):
                result = urllib.urlretrieve(request.META['HTTP_X_AUTH_PICTURE'])
                avatar = Avatar(user=user, primary=True)
                avatar.avatar.save("/var/askbot-site/askbot/upfiles/avatars/" + username[:username.find("@")], File(open(result[0])))
                avatar.save()
                sizes = avatar_settings.AVATAR_AUTO_GENERATE_SIZES
                for size in sizes:
                    avatar.create_thumbnail(size)
                user.avatar_type = 'a'
                user.clear_avatar_urls()
                user.save()
开发者ID:SaleCycle,项目名称:askbot-devel,代码行数:61,代码来源:remote_user.py

示例3: upload_avatar

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import create_thumbnail [as 别名]
def upload_avatar(request):
    '''
    Upload avatar
    :param request:
    :return:
    '''
    if request.method == 'POST':
        avatar_file = request.FILES['file']
        avatar = Avatar(
            user=request.user,
            primary=True,
        )
        try:
            avatar.avatar.delete()
        except Exception as e:
            # TODO log e
            pass
        avatar.avatar.save(avatar_file.name, avatar_file)
        avatar.save()
        avatar.create_thumbnail(80)
        return_data = json.dumps(
            {'status': 'success', 'thumbnail_url': avatar_url(request.user, 80)})
        return HttpResponse(return_data, mimetype='application/json')
    return HttpResponseNotAllowed(['POST', ])
开发者ID:ContributeToScience,项目名称:participant-booking-app,代码行数:26,代码来源:views.py


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