aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bn_django/photos/models.py6
-rw-r--r--bn_django/photos/urls.py2
-rw-r--r--bn_django/photos/views.py89
-rw-r--r--bn_django/settings.py.example3
4 files changed, 59 insertions, 41 deletions
diff --git a/bn_django/photos/models.py b/bn_django/photos/models.py
index fd31fa6..d6f9261 100644
--- a/bn_django/photos/models.py
+++ b/bn_django/photos/models.py
@@ -59,7 +59,7 @@ class Gallery(models.Model):
def __str__(self):
return self.title
def get_absolute_url(self):
- return "%s/%d/" % (STOCKPHOTO_URL, self.id)
+ return "%s/%s/" % (STOCKPHOTO_URL, self.slug)
def get_admin_url(self):
return "%s/photos/gallery/%d/" % (ADMIN_URL, self.id)
def was_published_today(self):
@@ -292,6 +292,6 @@ signals.pre_delete.connect(delete_thumbnails, sender=Photo)
from django.contrib import admin
-admin.site.register(Photo)
-admin.site.register(Gallery)
+#admin.site.register(Photo)
+#admin.site.register(Gallery)
diff --git a/bn_django/photos/urls.py b/bn_django/photos/urls.py
index af0c25a..233ccc4 100644
--- a/bn_django/photos/urls.py
+++ b/bn_django/photos/urls.py
@@ -18,6 +18,6 @@ urlpatterns = patterns('django.views.generic.list_detail',
dict(info_dict, queryset=Photo.objects.all())),
)
urlpatterns += patterns('bn_django.photos.views',
- (r'^import/[\d+]/$', 'import_photos'),
+ (r'^import/(?P<thegallery>\d+)/$', 'import_photos'),
#(r'^export/(\d+)/$', 'export'),
)
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'
diff --git a/bn_django/settings.py.example b/bn_django/settings.py.example
index 6ce8f3f..5a44c81 100644
--- a/bn_django/settings.py.example
+++ b/bn_django/settings.py.example
@@ -87,3 +87,6 @@ INSTALLED_APPS = (
'bn_django.git_browse',
'bn_django.journal',
)
+
+#Don't have much memory, so never use MemoryFileUploadHandler
+FILE_UPLOAD_HANDLERS = ("django.core.files.uploadhandler.TemporaryFileUploadHandler", )