summaryrefslogtreecommitdiff
path: root/app/photos/forms.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2015-12-13 08:36:51 -0500
committerluxagraf <sng@luxagraf.net>2015-12-13 08:36:51 -0500
commit2bc926fe3537363f6f5e6883d927120b8ada41da (patch)
tree3d0905719be8b571bbea357fa26ceb5e86b5b8fb /app/photos/forms.py
parent12100874dc8e713d1d4400bee285ba381f6f449c (diff)
added resizing function to photo uploads and changed wording on comments
template
Diffstat (limited to 'app/photos/forms.py')
-rw-r--r--app/photos/forms.py47
1 files changed, 26 insertions, 21 deletions
diff --git a/app/photos/forms.py b/app/photos/forms.py
index eae0e7e..6e299cd 100644
--- a/app/photos/forms.py
+++ b/app/photos/forms.py
@@ -11,24 +11,23 @@ try:
except ImportError:
from PIL import Image
-
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
-from django.contrib.sites.models import Site
-from django.conf import settings
-from django.utils.encoding import force_text
-from django.template.defaultfilters import slugify
from django.core.files.base import ContentFile
from django.contrib.admin import widgets
from django.contrib.gis.geos import Point
+from django.conf import settings
import exiftool
-from photos.models import LuxImage, Gallery
+from photos.models import LuxImage, LuxGallery
from locations.models import Location
+from .utils import resize_image
+
logger = logging.getLogger('photos.forms')
+
class UploadZipForm(forms.Form):
"""
Handles the uploading of a gallery of photos packed in a .zip file
@@ -60,7 +59,7 @@ class UploadZipForm(forms.Form):
def clean_title(self):
title = self.cleaned_data['title']
- if title and Gallery.objects.filter(title=title).exists():
+ if title and LuxGallery.objects.filter(title=title).exists():
raise forms.ValidationError(_('A gallery with that title already exists.'))
return title
@@ -78,11 +77,12 @@ class UploadZipForm(forms.Form):
if not zip_file:
zip_file = self.cleaned_data['zip_file']
- gallery, created = Gallery.objects.get_or_create(
- title= self.cleaned_data['title'],
- description = self.cleaned_data['desc'],
- slug= self.cleaned_data['slug'],
- pub_date= self.cleaned_data['date']
+ gallery, created = LuxGallery.objects.get_or_create(
+ title=self.cleaned_data['title'],
+ description=self.cleaned_data['desc'],
+ slug=self.cleaned_data['slug'],
+ pub_date=self.cleaned_data['date'],
+ is_public=self.cleaned_data['is_public']
)
zipper = zipfile.ZipFile(zip_file)
count = 1
@@ -124,8 +124,8 @@ class UploadZipForm(forms.Form):
continue
image = LuxImage(
- pub_date = datetime.datetime.now()
- )
+ pub_date=datetime.datetime.now()
+ )
contentfile = ContentFile(data)
image.image.save(filename, contentfile)
image.save()
@@ -136,11 +136,11 @@ class UploadZipForm(forms.Form):
et.terminate()
image.exif_raw = meta
try:
- image.title = meta["EXIF:ImageDescription"]
+ image.title = meta["EXIF:ImageDescription"]
except:
pass
try:
- image.caption = meta["EXIF:UserComment"]
+ image.caption = meta["EXIF:UserComment"]
except:
pass
try:
@@ -149,17 +149,17 @@ class UploadZipForm(forms.Form):
pass
try:
image.point = Point(meta["XMP:GPSLongitude"], meta["XMP:GPSLatitude"], srid=4326)
- try:
+ try:
image.location = Location.objects.filter(geometry__contains=image.point).get()
except Location.DoesNotExist:
pass
except KeyError:
pass
image.exif_aperture = meta["EXIF:FNumber"]
- image.exif_make = meta["EXIF:Make"]
- image.exif_model = meta["EXIF:Model"]
+ image.exif_make = meta["EXIF:Make"]
+ image.exif_model = meta["EXIF:Model"]
image.exif_exposure = str(Fraction(float(meta["EXIF:ExposureTime"])).limit_denominator())
- image.exif_iso = meta["EXIF:ISO"]
+ image.exif_iso = meta["EXIF:ISO"]
image.exif_focal_length = meta["EXIF:FocalLength"]
fmt_date = time.strptime(meta["EXIF:DateTimeOriginal"], "%Y:%m:%d %H:%M:%S")
image.exif_date = time.strftime("%Y-%m-%d %H:%M:%S", fmt_date)
@@ -167,7 +167,12 @@ class UploadZipForm(forms.Form):
image.width = meta["File:ImageWidth"]
image.save()
count += 1
-
+ img = Image.open(image.image.path)
+ base_path = "%s/galleries/" % settings.IMAGES_ROOT
+ resize_image(img, 2280, None, 65, base_path+'large/', image.get_image_name())
+ resize_image(img, 1140, None, 72, base_path+'medium/', image.get_image_name())
+ resize_image(img, 720, None, 68, base_path+'small/', image.get_image_name())
+
zipper.close()
if request: