aboutsummaryrefslogtreecommitdiffstats
path: root/bn_django
diff options
context:
space:
mode:
Diffstat (limited to 'bn_django')
-rw-r--r--bn_django/photos/urls.py2
-rw-r--r--bn_django/photos/views.py30
2 files changed, 14 insertions, 18 deletions
diff --git a/bn_django/photos/urls.py b/bn_django/photos/urls.py
index e9839b1..af0c25a 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/[\d+]/$', 'import_photos'),
#(r'^export/(\d+)/$', 'export'),
)
diff --git a/bn_django/photos/views.py b/bn_django/photos/views.py
index cf165cd..7955149 100644
--- a/bn_django/photos/views.py
+++ b/bn_django/photos/views.py
@@ -31,19 +31,15 @@ from bn_django.photos.models import Gallery, Photo
# views
-class ImportManipulator(forms.Manipulator):
- def __init__(self):
- self.fields = (
- forms.FileUploadField(field_name="zipfile",
- is_required=True,
- validator_list=[self.valid_zipfile,]),
- forms.TextField(field_name="photographer"),
- forms.DateField(field_name="date"),
- )
+class ImportForm(forms.Form):
+ zipfile = forms.FileField()
+ photographer = forms.CharField()
+ date = forms.DateField(widget=forms.DateInput)
+
def valid_zipfile(self, field_data, all_data):
zip_file = StringIO(field_data['content'])
- zip = zipfile.ZipFile(zip_file)
- return not zip.testzip()
+ zip = zipfile.ZipFile(zip_file)
+ return not zip.testzip()
@@ -73,12 +69,13 @@ def import_photos(request, thegallery):
if not request.user.has_perm('gallery.add_photo'):
return http.HttpResponseForbidden("No permission to add photos")
- manipulator = ImportManipulator()
if request.POST:
new_data = request.POST.copy()
new_data.update(request.FILES)
- errors = manipulator.get_validation_errors(new_data)
- if not errors:
+ 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)
@@ -125,7 +122,7 @@ def import_photos(request, thegallery):
if tags.has_key('Image Orientation'):
exifrot = tags['EXIF UserComment'].printable
- if exifrot = 'Rotated 90 CCW':
+ if exifrot == 'Rotated 90 CCW':
#DO ROTATION
continue
@@ -138,8 +135,7 @@ def import_photos(request, thegallery):
response['Cache-Control'] = 'no-cache'
return response
else:
- errors = new_data = {}
- form = forms.FormWrapper(manipulator, new_data, errors)
+ form = ImportForm()
return render_to_response('photos/import_form.html',
dict(form=form, gallery=gallery))
# request,