本文整理汇总了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)
示例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()
示例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', ])