new preference allowing to re-use existing file if it exists. might have concurrency issues since

we don't ask the database if it exists, only the storage system, so it might break if it's being
deleted at the same time
This commit is contained in:
Mathieu Pillard 2010-01-22 17:16:20 +01:00 committed by Eric Florenzano
parent dd1e3069ce
commit 5e804236a8
2 changed files with 8 additions and 2 deletions

View file

@ -17,6 +17,7 @@ AVATAR_DEFAULT_URL = getattr(settings, 'AVATAR_DEFAULT_URL',
AVATAR_MAX_AVATARS_PER_USER = getattr(settings, 'AVATAR_MAX_AVATARS_PER_USER', 42)
AVATAR_MAX_SIZE = getattr(settings, 'AVATAR_MAX_SIZE', 1024 * 1024)
AVATAR_THUMB_FORMAT = getattr(settings, 'AVATAR_THUMB_FORMAT', "JPEG")
AVATAR_DONT_SAVE_DUPLICATES = getattr(settings, 'AVATAR_DONT_SAVE_DUPLICATES', 0)
from django.db.models import signals
from django.contrib.auth.models import User

View file

@ -12,7 +12,7 @@ from django.db.models import get_app
from django.core.exceptions import ImproperlyConfigured
from django.conf import settings
from avatar import AVATAR_MAX_AVATARS_PER_USER
from avatar import AVATAR_MAX_AVATARS_PER_USER, AVATAR_DONT_SAVE_DUPLICATES
try:
notification = get_app('notification')
@ -79,7 +79,12 @@ def add(request, extra_context={}, next_override=None):
primary = True,
avatar = path,
)
new_file = avatar.avatar.storage.save(path, request.FILES['avatar'])
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'])
avatar.save()
updated = True
request.user.message_set.create(