Exemplo n.º 1
0
 def create_thumbnail(self, size, quality=None):
     # invalidate the cache of the thumbnail with the given size first
     if isinstance(self, Avatar):
         invalidate_cache(self.emailuser, size)
         
     try:
         orig = self.avatar.storage.open(self.avatar.name, 'rb').read()
         image = Image.open(StringIO(orig))
     except IOError:
         return # What should we do here?  Render a "sorry, didn't work" img?
     quality = quality or AVATAR_THUMB_QUALITY
     (w, h) = image.size
     if w != size or h != size:
         if w > h:
             diff = (w - h) / 2
             image = image.crop((diff, 0, w - diff, h))
         else:
             diff = (h - w) / 2
             image = image.crop((0, diff, w, h - diff))
         if image.mode != "RGBA":
             image = image.convert("RGBA")
         image = image.resize((size, size), AVATAR_RESIZE_METHOD)
         thumb = StringIO()
         image.save(thumb, AVATAR_THUMB_FORMAT, quality=quality)
         thumb_file = ContentFile(thumb.getvalue())
     else:
         thumb_file = ContentFile(orig)
     thumb = self.avatar.storage.save(self.avatar_name(size), thumb_file)
Exemplo n.º 2
0
 def create_thumbnail(self, size, quality=None):
     # invalidate the cache of the thumbnail with the given size first
     if isinstance(self, Avatar):
         invalidate_cache(self.emailuser, size)
         
     try:
         orig = self.avatar.storage.open(self.avatar.name, 'rb').read()
         image = Image.open(StringIO(orig))
     except IOError:
         return # What should we do here?  Render a "sorry, didn't work" img?
     quality = quality or AVATAR_THUMB_QUALITY
     (w, h) = image.size
     if w != size or h != size:
         if w > h:
             diff = (w - h) / 2
             image = image.crop((diff, 0, w - diff, h))
         else:
             diff = (h - w) / 2
             image = image.crop((0, diff, w, h - diff))
         if image.mode != "RGBA":
             image = image.convert("RGBA")
         image = image.resize((size, size), AVATAR_RESIZE_METHOD)
         thumb = StringIO()
         image.save(thumb, AVATAR_THUMB_FORMAT, quality=quality)
         thumb_file = ContentFile(thumb.getvalue())
     else:
         thumb_file = ContentFile(orig)
     thumb = self.avatar.storage.save(self.avatar_name(size), thumb_file)
Exemplo n.º 3
0
 def save(self, *args, **kwargs):
     avatars = Avatar.objects.filter(emailuser=self.emailuser)
     if not self.pk:
         avatars.delete()
     else:
         avatars.exclude(pk=self.pk).delete()
     invalidate_cache(self.emailuser)
     super(Avatar, self).save(*args, **kwargs)
Exemplo n.º 4
0
 def save(self, *args, **kwargs):
     avatars = Avatar.objects.filter(emailuser=self.emailuser)
     if self.pk:
         avatars = avatars.exclude(pk=self.pk)
     if AVATAR_MAX_AVATARS_PER_USER > 1:
         if self.primary:
             avatars = avatars.filter(primary=True)
             avatars.update(primary=False)
     else:
         avatars.delete()
     invalidate_cache(self.emailuser)
     super(Avatar, self).save(*args, **kwargs)
Exemplo n.º 5
0
 def save(self, *args, **kwargs):
     avatars = Avatar.objects.filter(emailuser=self.emailuser)
     if self.pk:
         avatars = avatars.exclude(pk=self.pk)
     if AVATAR_MAX_AVATARS_PER_USER > 1:
         if self.primary:
             avatars = avatars.filter(primary=True)
             avatars.update(primary=False)
     else:
         avatars.delete()
     invalidate_cache(self.emailuser)
     super(Avatar, self).save(*args, **kwargs)
Exemplo n.º 6
0
 def delete(self, *args, **kwargs):
     invalidate_cache(self.emailuser)
     super(Avatar, self).delete(*args, **kwargs)
Exemplo n.º 7
0
 def delete(self, *args, **kwargs):
     invalidate_cache(self.emailuser)
     super(Avatar, self).delete(*args, **kwargs)