summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2016-04-02 21:06:24 -0400
committerluxagraf <sng@luxagraf.net>2016-04-02 21:06:24 -0400
commit062a09fc40049f2d7de58834556dc3e8b80870ff (patch)
tree267a911168e52bb40615c87d66c30ebebe9390ee /app
parent253bf55fea70b646c7306918d2d6b3ec9d2f3b10 (diff)
added basic video uploading capabilities to gallery upload tool
Diffstat (limited to 'app')
-rw-r--r--app/photos/forms.py58
-rw-r--r--app/photos/models.py48
2 files changed, 55 insertions, 51 deletions
diff --git a/app/photos/forms.py b/app/photos/forms.py
index 16ba890..4e00189 100644
--- a/app/photos/forms.py
+++ b/app/photos/forms.py
@@ -125,41 +125,41 @@ class UploadZipForm(forms.Form):
logger.debug('File "{0}" is empty.'.format(filename))
continue
- # Basic check that we have a valid image.
- try:
- file = BytesIO(data)
- opened = Image.open(file)
- opened.verify()
- except Exception:
- # Pillow (or PIL) doesn't recognize it as an image.
- # If a "bad" file is found we just skip it.
- # But we do flag this both in the logs and to the user.
- logger.error('Could not process file "{0}" in the .zip archive.'.format(
- filename))
- if request:
- messages.warning(request,
- _('Could not process file "{0}" in the .zip archive.').format(
- filename),
- fail_silently=True)
- continue
-
+ fn, file_extension = os.path.splitext(filename)
+ if file_extension != ".mp4":
+ # Basic check that we have a valid image.
+ try:
+ file = BytesIO(data)
+ opened = Image.open(file)
+ opened.verify()
+ except Exception:
+ # Pillow (or PIL) doesn't recognize it as an image.
+ # If a "bad" file is found we just skip it.
+ # But we do flag this both in the logs and to the user.
+ logger.error('Could not process file "{0}" in the .zip archive.'.format(filename))
+ if request:
+ messages.warning(request,
+ _('Could not process file "{0}" in the .zip archive.').format(
+ filename),
+ fail_silently=True)
+ continue
image = LuxImage(
pub_date=datetime.datetime.now()
)
contentfile = ContentFile(data)
image.image.save(filename, contentfile)
- img = Image.open(image.image.path)
- if img.size[0] > img.size[1]:
- image.sizes.add(LuxImageSize.objects.get(width=2280))
- image.sizes.add(LuxImageSize.objects.get(width=1140))
- image.sizes.add(LuxImageSize.objects.get(width=720))
- if img.size[1] > img.size[0]:
- image.sizes.add(LuxImageSize.objects.get(width=1600))
- image.sizes.add(LuxImageSize.objects.get(width=800))
- image.sizes.add(LuxImageSize.objects.get(width=460))
- image.save()
+ if file_extension != ".mp4":
+ img = Image.open(image.image.path)
+ if img.size[0] > img.size[1]:
+ image.sizes.add(LuxImageSize.objects.get(width=2280))
+ image.sizes.add(LuxImageSize.objects.get(width=1140))
+ image.sizes.add(LuxImageSize.objects.get(width=720))
+ if img.size[1] > img.size[0]:
+ image.sizes.add(LuxImageSize.objects.get(width=1600))
+ image.sizes.add(LuxImageSize.objects.get(width=800))
+ image.sizes.add(LuxImageSize.objects.get(width=460))
+ image.save()
gallery.images.add(image)
- base_path = "%s/galleries/" % settings.IMAGES_ROOT
zipper.close()
diff --git a/app/photos/models.py b/app/photos/models.py
index 3ae58e4..50f2aa4 100644
--- a/app/photos/models.py
+++ b/app/photos/models.py
@@ -57,7 +57,7 @@ class LuxImage(models.Model):
location = models.ForeignKey(Location, null=True, blank=True)
is_public = models.BooleanField(default=True)
is_video = models.BooleanField(default=False)
- sizes = models.ManyToManyField(LuxImageSize)
+ sizes = models.ManyToManyField(LuxImageSize, blank=True)
flickr_id = models.CharField(null=True, blank=True, max_length=80)
class Meta:
@@ -115,32 +115,36 @@ class LuxImage(models.Model):
@receiver(post_save, sender=LuxImage)
def post_save_events(sender, update_fields, created, instance, **kwargs):
- instance = readexif(instance)
- post_save.disconnect(post_save_events, sender=LuxImage)
- instance.save()
- post_save.connect(post_save_events, sender=LuxImage)
+ filename, file_extension = os.path.splitext(instance.image.path)
+ if file_extension != ".mp4":
+ instance = readexif(instance)
+ post_save.disconnect(post_save_events, sender=LuxImage)
+ instance.save()
+ post_save.connect(post_save_events, sender=LuxImage)
@receiver(m2m_changed, sender=LuxImage.sizes.through)
def update_photo_sizes(sender, instance, **kwargs):
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():
- 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)
+ filename, file_extension = os.path.splitext(instance.image.path)
+ if file_extension != ".mp4":
+ 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():
+ 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):