Handle image reupload correctly.
authorRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Mon, 3 Feb 2014 10:02:40 +0000 (11:02 +0100)
committerRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Mon, 3 Feb 2014 10:02:40 +0000 (11:02 +0100)
apps/cover/forms.py
apps/cover/templates/cover/add_image.html
apps/cover/templates/cover/image_detail.html
apps/cover/views.py

index 4c71886..5b514f0 100755 (executable)
@@ -15,7 +15,7 @@ class ImageAddForm(forms.ModelForm):
 
     def __init__(self, *args, **kwargs):
         super(ImageAddForm, self).__init__(*args, **kwargs)
-        self.fields['file'].required = self.fields['download_url'].required = self.fields['source_url'].required = False
+        self.fields['file'].required = False
 
     def clean_download_url(self):
         return self.cleaned_data['download_url'] or None
@@ -38,7 +38,7 @@ class ImageEditForm(forms.ModelForm):
 
 
 class ReadonlyImageEditForm(ImageEditForm):
-    """Form used for not editing a Book."""
+    """Form used for not editing an Image."""
 
     def __init__(self, *args, **kwargs):
         ret = super(ReadonlyImageEditForm, self).__init__(*args, **kwargs)
index 1854555..9e3c71d 100755 (executable)
@@ -58,7 +58,7 @@
         <th>{{ form.file.errors }} <input style="width: auto;" data-for="id_file" type="radio" name="upload_type" value="file"/> Lub {{form.file.label}}</th>
         <td>{{form.file}}</td>
 
-    </td>
+    </tr>
     <tr><td></td><td><button type="submit">{% trans "Add image" %}</button></td></tr>
 </tbody></table>
 </form>
index 5707b29..57bd0b4 100755 (executable)
@@ -9,7 +9,7 @@
 <div style="float: right; margin-bottom:1em;">
 
 <a href="{{ object.file.url }}"><img style="width:400px"
-        src="{% thumbnail object.file "400x" as thumb %}
+        src="{% thumbnail object.file "400x400" as thumb %}
                 {{ thumb.url }}
              {% empty %}
                 {{ object.file.url }}
     </a>
 <br/><a href="{{ object.source_url }}">{{ object.title }}</a> by {{ object.author }},
     {% if object.license_url %}<a href="{{ object.license_url }}">{% endif %}
-        {{ object.license_name }}</a>
+        {{ object.license_name }}
     {% if object.license_url %}</a>{% endif %}
 
 <br/>{% trans "source" %}: {{ object.download_url }}
 </div>
 
 
-{% if editable %}<form method="post">{% csrf_token %}{% endif %}
+{% if editable %}
+    <form method="post" enctype="multipart/form-data">
+    {% csrf_token %}
+    {{ form.non_field_errors }}
+{% endif %}
 <table class='editable'><tbody>
     {{ form.as_table }}
     {% if editable %}
index 4bb6d50..6b3344b 100644 (file)
@@ -87,7 +87,7 @@ def image(request, pk):
 
     if request.user.has_perm('cover.change_image'):
         if request.method == "POST":
-            form = forms.ImageEditForm(request.POST, instance=image)
+            form = forms.ImageEditForm(request.POST, request.FILES, instance=image)
             if form.is_valid():
                 form.save()
                 return HttpResponseRedirect(image.get_absolute_url())