Commit 7e335cfb authored by Skia's avatar Skia

Update rotating function

parent 00feca44
...@@ -60,13 +60,13 @@ class Picture(SithFile): ...@@ -60,13 +60,13 @@ class Picture(SithFile):
def rotate(self, degree): def rotate(self, degree):
for attr in ['file', 'compressed', 'thumbnail']: for attr in ['file', 'compressed', 'thumbnail']:
if self.__getattribute__(attr): name = self.__getattribute__(attr).name
im = Image.open(BytesIO(self.__getattribute__(attr).read())) with open((settings.MEDIA_ROOT + name).encode('utf-8'), 'r+b') as file:
new_image = BytesIO() if file:
im = im.rotate(degree, expand=True) im = Image.open(BytesIO(file.read()))
im.save(fp=new_image, format=self.mime_type.split('/')[-1].upper(), quality=90, optimize=True, progressive=True) file.seek(0)
self.__getattribute__(attr).save(self.name, ContentFile(new_image.getvalue())) im = im.rotate(degree, expand=True)
self.save() im.save(fp=file, format=self.mime_type.split('/')[-1].upper(), quality=90, optimize=True, progressive=True)
def get_next(self): def get_next(self):
return self.parent.children.filter(is_moderated=True, asked_for_removal=False, is_folder=False, return self.parent.children.filter(is_moderated=True, asked_for_removal=False, is_folder=False,
...@@ -90,6 +90,9 @@ class Album(SithFile): ...@@ -90,6 +90,9 @@ class Album(SithFile):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('sas:album', kwargs={'album_id': self.id}) return reverse('sas:album', kwargs={'album_id': self.id})
def get_download_url(self):
return reverse('sas:download', kwargs={'picture_id': self.id})
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment