From ee4f3e79135a34ad7ed845453adbe8dfc1e420c1 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 3 Feb 2014 11:02:40 +0100 Subject: [PATCH] Handle image reupload correctly. --- apps/cover/forms.py | 4 ++-- apps/cover/templates/cover/add_image.html | 2 +- apps/cover/templates/cover/image_detail.html | 10 +++++++--- apps/cover/views.py | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/cover/forms.py b/apps/cover/forms.py index 4c718862..5b514f08 100755 --- a/apps/cover/forms.py +++ b/apps/cover/forms.py @@ -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) diff --git a/apps/cover/templates/cover/add_image.html b/apps/cover/templates/cover/add_image.html index 1854555f..9e3c71d7 100755 --- a/apps/cover/templates/cover/add_image.html +++ b/apps/cover/templates/cover/add_image.html @@ -58,7 +58,7 @@ {{ form.file.errors }} Lub {{form.file.label}} {{form.file}} - + diff --git a/apps/cover/templates/cover/image_detail.html b/apps/cover/templates/cover/image_detail.html index 5707b29e..57bd0b49 100755 --- a/apps/cover/templates/cover/image_detail.html +++ b/apps/cover/templates/cover/image_detail.html @@ -9,7 +9,7 @@

{{ object.title }} by {{ object.author }}, {% if object.license_url %}{% endif %} - {{ object.license_name }} + {{ object.license_name }} {% if object.license_url %}{% endif %}
{% trans "source" %}: {{ object.download_url }}
-{% if editable %}
{% csrf_token %}{% endif %} +{% if editable %} + + {% csrf_token %} + {{ form.non_field_errors }} +{% endif %} {{ form.as_table }} {% if editable %} diff --git a/apps/cover/views.py b/apps/cover/views.py index 4bb6d504..6b3344b4 100644 --- a/apps/cover/views.py +++ b/apps/cover/views.py @@ -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()) -- 2.20.1