mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
Simplify image handling. Breaks the new AVATAR_DONT_SAVE_DUPLICATES setting but I will revisit it later in a cleaner way
This commit is contained in:
parent
8a680ecd66
commit
0b5674f008
2 changed files with 3 additions and 11 deletions
|
|
@ -20,8 +20,7 @@ from avatar import AVATAR_STORAGE_DIR, AVATAR_RESIZE_METHOD, \
|
|||
AVATAR_MAX_AVATARS_PER_USER, AVATAR_THUMB_FORMAT
|
||||
|
||||
|
||||
def avatar_file_path(instance=None, filename=None, user=None):
|
||||
user = user or instance.user
|
||||
def avatar_file_path(instance=None, filename=None):
|
||||
return os.path.join(AVATAR_STORAGE_DIR, user.username, filename)
|
||||
|
||||
class Avatar(models.Model):
|
||||
|
|
|
|||
|
|
@ -72,19 +72,12 @@ def add(request, extra_context={}, next_override=None):
|
|||
request.FILES or None, user=request.user)
|
||||
if request.method == "POST" and 'avatar' in request.FILES:
|
||||
if upload_avatar_form.is_valid():
|
||||
path = avatar_file_path(user=request.user,
|
||||
filename=request.FILES['avatar'].name)
|
||||
avatar = Avatar(
|
||||
user = request.user,
|
||||
primary = True,
|
||||
avatar = path,
|
||||
)
|
||||
if AVATAR_DONT_SAVE_DUPLICATES and \
|
||||
avatar.avatar.storage.exists(path):
|
||||
new_file = None
|
||||
else:
|
||||
new_file = avatar.avatar.storage.save(path,
|
||||
request.FILES['avatar'])
|
||||
image_file = request.FILES['avatar']
|
||||
avatar.avatar.save(image_file.name, image_file)
|
||||
avatar.save()
|
||||
updated = True
|
||||
request.user.message_set.create(
|
||||
|
|
|
|||
Loading…
Reference in a new issue