Auto generate album thumbnails

This commit is contained in:
Skia 2016-12-18 18:34:48 +01:00
parent 94e740fb04
commit dd2be2a31e
2 changed files with 9 additions and 0 deletions

View File

@ -111,6 +111,14 @@ class Album(SithFile):
def get_download_url(self): def get_download_url(self):
return reverse('sas:download', kwargs={'picture_id': self.id}) return reverse('sas:download', kwargs={'picture_id': self.id})
def generate_thumbnail(self):
p = self.children_pictures.order_by('?').first() or self.children_albums.exclude(file=None).exclude(file="").order_by('?').first()
if p and p.file:
im = Image.open(BytesIO(p.file.read()))
self.file = resize_image(im, 200, "jpeg")
self.file.name = self.name + '/thumb.jpg'
self.save()
class PeoplePictureRelation(models.Model): class PeoplePictureRelation(models.Model):
""" """
The PeoplePictureRelation class makes the connection between User and Picture The PeoplePictureRelation class makes the connection between User and Picture

View File

@ -162,6 +162,7 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
self.object.generate_thumbnail()
self.form = self.get_form() self.form = self.get_form()
if 'clipboard' not in request.session.keys(): if 'clipboard' not in request.session.keys():
request.session['clipboard'] = [] request.session['clipboard'] = []