aboutsummaryrefslogtreecommitdiffstats
path: root/bn_django/photos/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'bn_django/photos/views.py')
-rw-r--r--bn_django/photos/views.py89
1 files changed, 52 insertions, 37 deletions
diff --git a/bn_django/photos/views.py b/bn_django/photos/views.py
index 7955149..993c116 100644
--- a/bn_django/photos/views.py
+++ b/bn_django/photos/views.py
@@ -34,15 +34,13 @@ from bn_django.photos.models import Gallery, Photo
class ImportForm(forms.Form):
zipfile = forms.FileField()
photographer = forms.CharField()
- date = forms.DateField(widget=forms.DateInput)
+ date = forms.DateField()
def valid_zipfile(self, field_data, all_data):
zip_file = StringIO(field_data['content'])
zip = zipfile.ZipFile(zip_file)
return not zip.testzip()
-
-
@login_required
def import_photos(request, thegallery):
"""Import a batch of photographs uploaded by the user.
@@ -70,25 +68,23 @@ def import_photos(request, thegallery):
return http.HttpResponseForbidden("No permission to add photos")
if request.POST:
- new_data = request.POST.copy()
- new_data.update(request.FILES)
+ #new_data = request.POST.copy()
+ #new_data.update(request.FILES)
form = ImportForm(request.POST, request.FILES)
if not form.is_valid():
return render_to_response('photos/import_form.html',
dict(form=form, gallery=gallery))
- # So now everything is okay
- f = StringIO(new_data['zipfile']['content']) # the zip"file"
- zip = zipfile.ZipFile(f)
- manipulator.do_html2python(new_data)
- date = new_data['date']
- if not date:
- date = datetime.date(datetime.now())
-
- destdir= os.path.join(settings.MEDIA_ROOT, STOCKPHOTO_BASE,
- datetime.strftime(datetime.now(),
- "%Y/%m/%d/"))
- if not os.path.isdir(destdir):
- os.makedirs(destdir, 0775)
+ # So now everything is okay
+ f = request.FILES['zipfile'] # the zip"file"
+ zip = zipfile.ZipFile(f)
+ date = request.POST['date']
+ if not date:
+ date = datetime.date(datetime.now())
+ destdir= os.path.join(settings.MEDIA_ROOT, STOCKPHOTO_BASE,
+ datetime.strftime(datetime.now(), "%Y/%m/%d/"))
+
+ if not os.path.isdir(destdir):
+ os.makedirs(destdir, 0775)
for filename in zip.namelist():
photopath = os.path.join(destdir, os.path.basename(filename))
data = zip.read(filename)
@@ -106,29 +102,48 @@ def import_photos(request, thegallery):
if photopath.startswith(os.path.sep):
photopath = photopath[len(settings.MEDIA_ROOT):]
photo = Photo(image=photopath, date=date,
- photographer=new_data['photographer'],
- title = os.path.basename(filename),
+ photographer=request.POST['photographer'],
+ title = 'untitled',
gallery_id = thegallery)
- # Try to harvest EXIF data
- import EXIF
- tags = EXIF.process_file(f)
- if tags.has_key('Image DateTime'):
- exifdate = tags['Image DateTime'].printable
- photo.date = apply(datetime.date, map(int, exifdate.values.split(' ')[0].split(':')))
- if tags.has_key('EXIF UserComment'):
- exiftitle = tags['EXIF UserComment'].printable
- photo.title = exiftitle
-
- if tags.has_key('Image Orientation'):
- exifrot = tags['EXIF UserComment'].printable
- if exifrot == 'Rotated 90 CCW':
- #DO ROTATION
- continue
-
# Save it -- the thumbnails etc. get created.
photo.save()
-
+
+ # Try to harvest EXIF data
+ try:
+ import EXIF
+ tags = EXIF.process_file(open(photo.image.path))
+ try:
+ if tags.has_key('Image DateTime'):
+ exifdate = tags['Image DateTime'].printable
+ photo.date = apply(datetime, map(int, exifdate.split(' ')[0].split(':')))
+ except Exception as E:
+ print E
+ pass
+ try:
+ if tags.has_key('EXIF UserComment'):
+ exiftitle = tags['EXIF UserComment'].printable
+ if not exiftitle == []:
+ photo.title = exiftitle
+
+ except Exception as E:
+ print E
+ pass
+ try:
+ if tags.has_key('Image Orientation'):
+ exifrot = tags['EXIF UserComment'].printable
+ if exifrot == 'Rotated 90 CCW':
+ #DO ROTATION
+ pass
+ except Exception as E:
+ print E
+ pass
+ except Exception as E:
+ print E
+ pass
+ finally:
+ photo.save()
+
# And jump to the directory for this gallery
response = http.HttpResponseRedirect(gallery.get_absolute_url())
response['Pragma'] = 'no cache'