From a22f1bea8167e77a7866353db473dfdb4a4161f3 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sun, 23 Aug 2009 00:21:48 +0300 Subject: first whack at fixing bulk photo uploads --- bn_django/photos/templates/photos/import_form.html | 3 +++ bn_django/photos/urls.py | 6 +++--- bn_django/photos/views.py | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) (limited to 'bn_django') diff --git a/bn_django/photos/templates/photos/import_form.html b/bn_django/photos/templates/photos/import_form.html index 0d4f19e..bd01a9a 100644 --- a/bn_django/photos/templates/photos/import_form.html +++ b/bn_django/photos/templates/photos/import_form.html @@ -51,6 +51,9 @@ you can change any of these settings on a per-photo basis after you upload the images.

+

+ UPDATE: The title and rotation will be guessed from EXIF data... +

{% else %}

Oops! No gallery here!

diff --git a/bn_django/photos/urls.py b/bn_django/photos/urls.py index f50a97b..e9839b1 100644 --- a/bn_django/photos/urls.py +++ b/bn_django/photos/urls.py @@ -17,7 +17,7 @@ urlpatterns = patterns('django.views.generic.list_detail', (r'^detail/(?P\d+)/$', 'object_detail', dict(info_dict, queryset=Photo.objects.all())), ) -#urlpatterns += patterns('bn_django.photos.views', - #(r'^import/(\d+)/$', 'import_photos'), +urlpatterns += patterns('bn_django.photos.views', + (r'^import/(\d+)/$', 'import_photos'), #(r'^export/(\d+)/$', 'export'), -#) +) diff --git a/bn_django/photos/views.py b/bn_django/photos/views.py index bc8a3a4..cf165cd 100644 --- a/bn_django/photos/views.py +++ b/bn_django/photos/views.py @@ -103,6 +103,7 @@ def import_photos(request, thegallery): continue photo = file(photopath, "wb") photo.write(data) + f = photo # Create the object if photopath.startswith(os.path.sep): @@ -111,6 +112,23 @@ def import_photos(request, thegallery): photographer=new_data['photographer'], title = os.path.basename(filename), 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() -- cgit v1.2.3