fnp
/
redakcja.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b0a8c8c
)
Handle image reupload correctly.
author
Radek Czajka
<radekczajka@nowoczesnapolska.org.pl>
Mon, 3 Feb 2014 10:02:40 +0000
(11:02 +0100)
committer
Radek Czajka
<radekczajka@nowoczesnapolska.org.pl>
Mon, 3 Feb 2014 10:02:40 +0000
(11:02 +0100)
apps/cover/forms.py
patch
|
blob
|
history
apps/cover/templates/cover/add_image.html
patch
|
blob
|
history
apps/cover/templates/cover/image_detail.html
patch
|
blob
|
history
apps/cover/views.py
patch
|
blob
|
history
diff --git
a/apps/cover/forms.py
b/apps/cover/forms.py
index
4c71886
..
5b514f0
100755
(executable)
--- 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)
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
def clean_download_url(self):
return self.cleaned_data['download_url'] or None
@@
-38,7
+38,7
@@
class ImageEditForm(forms.ModelForm):
class ReadonlyImageEditForm(ImageEditForm):
class ReadonlyImageEditForm(ImageEditForm):
- """Form used for not editing a
Book
."""
+ """Form used for not editing a
n Image
."""
def __init__(self, *args, **kwargs):
ret = super(ReadonlyImageEditForm, self).__init__(*args, **kwargs)
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
1854555
..
9e3c71d
100755
(executable)
--- a/
apps/cover/templates/cover/add_image.html
+++ b/
apps/cover/templates/cover/add_image.html
@@
-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>
<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>
- </t
d
>
+ </t
r
>
<tr><td></td><td><button type="submit">{% trans "Add image" %}</button></td></tr>
</tbody></table>
</form>
<tr><td></td><td><button type="submit">{% trans "Add image" %}</button></td></tr>
</tbody></table>
</form>
diff --git
a/apps/cover/templates/cover/image_detail.html
b/apps/cover/templates/cover/image_detail.html
index
5707b29
..
57bd0b4
100755
(executable)
--- a/
apps/cover/templates/cover/image_detail.html
+++ b/
apps/cover/templates/cover/image_detail.html
@@
-9,7
+9,7
@@
<div style="float: right; margin-bottom:1em;">
<a href="{{ object.file.url }}"><img style="width:400px"
<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 "400x
400
" as thumb %}
{{ thumb.url }}
{% empty %}
{{ object.file.url }}
{{ thumb.url }}
{% empty %}
{{ object.file.url }}
@@
-17,14
+17,18
@@
</a>
<br/><a href="{{ object.source_url }}">{{ object.title }}</a> by {{ object.author }},
{% if object.license_url %}<a href="{{ object.license_url }}">{% endif %}
</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 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 %}
<table class='editable'><tbody>
{{ form.as_table }}
{% if editable %}
diff --git
a/apps/cover/views.py
b/apps/cover/views.py
index
4bb6d50
..
6b3344b
100644
(file)
--- 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":
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())
if form.is_valid():
form.save()
return HttpResponseRedirect(image.get_absolute_url())