mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
This time it should really work in every case... I hope. This really needs some unit tests.
This commit is contained in:
parent
84aa3b84d3
commit
b2f3bec769
2 changed files with 9 additions and 5 deletions
|
|
@ -28,7 +28,8 @@ class UploadAvatarForm(forms.Form):
|
|||
"Your file is too big (%s), the maximum allowed size is %s" %
|
||||
(filesizeformat(data.size), filesizeformat(AVATAR_MAX_SIZE)))
|
||||
count = Avatar.objects.filter(user=self.user).count()
|
||||
if count >= AVATAR_MAX_AVATARS_PER_USER:
|
||||
if AVATAR_MAX_AVATARS_PER_USER > 1 and \
|
||||
count >= AVATAR_MAX_AVATARS_PER_USER:
|
||||
raise forms.ValidationError(
|
||||
"You already have %d avatars, and the maximum allowed is %d." %
|
||||
(count, AVATAR_MAX_AVATARS_PER_USER))
|
||||
|
|
|
|||
|
|
@ -33,10 +33,13 @@ class Avatar(models.Model):
|
|||
return _(u'Avatar for %s') % self.user
|
||||
|
||||
def save(self, force_insert=False, force_update=False):
|
||||
if self.primary:
|
||||
avatars = Avatar.objects.filter(user=self.user, primary=True)\
|
||||
.exclude(id=self.id)
|
||||
avatars.update(primary=False)
|
||||
avatars = Avatar.objects.filter(user=self.user).exclude(id=self.id)
|
||||
if AVATAR_MAX_AVATARS_PER_USER > 1:
|
||||
if instance.primary:
|
||||
avatars = avatars.filter(primary=True)
|
||||
avatars.update(primary=False)
|
||||
else:
|
||||
avatars.delete()
|
||||
super(Avatar, self).save(force_insert, force_update)
|
||||
|
||||
def thumbnail_exists(self, size):
|
||||
|
|
|
|||
Loading…
Reference in a new issue