summaryrefslogtreecommitdiff
path: root/app/photos/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/photos/models.py')
-rw-r--r--app/photos/models.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/app/photos/models.py b/app/photos/models.py
index 6907a25..3ae58e4 100644
--- a/app/photos/models.py
+++ b/app/photos/models.py
@@ -10,6 +10,8 @@ from django.conf import settings
from taggit.managers import TaggableManager
from locations.models import Location, Region
+from resizeimage.imageexceptions import ImageSizeError
+
from .utils import resize_image
from .readexif import readexif
from django.db.models.signals import post_save
@@ -121,13 +123,24 @@ def post_save_events(sender, update_fields, created, instance, **kwargs):
@receiver(m2m_changed, sender=LuxImage.sizes.through)
def update_photo_sizes(sender, instance, **kwargs):
- print("hellow world")
base_path = "%s/%s/" % (settings.IMAGES_ROOT, instance.pub_date.strftime("%Y"))
img = Image.open(instance.image.path)
resize_image(img, 160, None, 78, base_path, "%s_tn.%s" % (instance.get_image_name(), instance.get_image_ext()))
for size in instance.sizes.all():
- print(size.width)
- resize_image(img, size.width, None, size.quality, base_path, "%s_%s.%s" % (instance.get_image_name(), size.width, instance.get_image_ext()))
+ if img.size[0] > img.size[1]:
+ try:
+ resize_image(img, size.width, None, size.quality, base_path, "%s_%s.%s" % (instance.get_image_name(), size.width, instance.get_image_ext()))
+ except ImageSizeError:
+ m2m_changed.disconnect(update_photo_sizes, sender=LuxImage.sizes.through)
+ instance.sizes.remove(size)
+ m2m_changed.connect(update_photo_sizes, sender=LuxImage.sizes.through)
+ if img.size[1] > img.size[0]:
+ try:
+ resize_image(img, None, size.width, size.quality, base_path, "%s_%s.%s" % (instance.get_image_name(), size.width, instance.get_image_ext()))
+ except ImageSizeError:
+ m2m_changed.disconnect(update_photo_sizes, sender=LuxImage.sizes.through)
+ instance.sizes.remove(size)
+ m2m_changed.connect(update_photo_sizes, sender=LuxImage.sizes.through)
class LuxGallery(models.Model):