mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
Auto generate album thumbnails
This commit is contained in:
parent
94e740fb04
commit
dd2be2a31e
@ -111,6 +111,14 @@ class Album(SithFile):
|
||||
def get_download_url(self):
|
||||
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):
|
||||
"""
|
||||
The PeoplePictureRelation class makes the connection between User and Picture
|
||||
|
@ -162,6 +162,7 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
self.object.generate_thumbnail()
|
||||
self.form = self.get_form()
|
||||
if 'clipboard' not in request.session.keys():
|
||||
request.session['clipboard'] = []
|
||||
|
Loading…
Reference in New Issue
Block a user