commit
c1dc3790c0
|
@ -122,6 +122,7 @@ class EditionForm(forms.ModelForm):
|
|||
)
|
||||
language = forms.ChoiceField(choices=LANGUAGES)
|
||||
description = forms.CharField( required=False, widget= forms.Textarea(attrs={'cols': 80, 'rows': 2}))
|
||||
coverfile = forms.ImageField(required=False)
|
||||
|
||||
def clean(self):
|
||||
if not self.cleaned_data.get("isbn",False) and not self.cleaned_data.get("oclc",False) and not self.cleaned_data.get("goog",False):
|
||||
|
@ -136,6 +137,7 @@ class EditionForm(forms.ModelForm):
|
|||
'add_author': forms.TextInput(attrs={'size': 30}),
|
||||
'add_subject': forms.TextInput(attrs={'size': 30}),
|
||||
'unglued': forms.CheckboxInput(),
|
||||
'cover_image': forms.TextInput(attrs={'size': 60}),
|
||||
}
|
||||
|
||||
class EbookFileForm(forms.ModelForm):
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
{% endif %}
|
||||
|
||||
<p>Title and ISBN 13 are required; the rest is optional, though a cover image link is strongly recommended.</p>
|
||||
<form method="POST" action="#">
|
||||
<form enctype="multipart/form-data" method="POST" action="#">
|
||||
{% csrf_token %}
|
||||
{{ form.work }}
|
||||
{{ form.non_field_errors }}
|
||||
|
@ -26,7 +26,7 @@
|
|||
|
||||
<p>
|
||||
<b>Authors</b>:
|
||||
{% if edition.authors or edition.new_author_names %}
|
||||
{% if edition.pk and edition.authors or edition.new_author_names %}
|
||||
<ul>
|
||||
{% if edition.pk and edition.authors %}
|
||||
{% for author in edition.authors.all %}
|
||||
|
@ -61,7 +61,7 @@
|
|||
|
||||
<p><b>Publisher</b>: {{ form.publisher.errors }}{{ form.publisher }}</p>
|
||||
|
||||
<p><b>Publish Date</b> (<I>four-digit year</I>): {{ form.publication_date.errors }}{{ form.publication_date }}</p>
|
||||
<p><b>Publication Date</b> (<I>four-digit year</I>): {{ form.publication_date.errors }}{{ form.publication_date }}</p>
|
||||
|
||||
<p><b>Public Domain?</b>: {{ form.public_domain.errors }}{{ form.public_domain }}</p>
|
||||
{% comment %}
|
||||
|
@ -69,7 +69,7 @@
|
|||
|
||||
<p><b>Subjects</b>:
|
||||
<ul>
|
||||
{% if edition.work.subjects %}
|
||||
{% if edition.work.pk and edition.work.subjects %}
|
||||
{% for subject in edition.work.subjects.all %}
|
||||
<li>{{ subject.name }}</li>
|
||||
{% endfor %}
|
||||
|
@ -81,8 +81,19 @@
|
|||
<b>Add a Subject</b>: {{ form.add_subject.errors }}{{ form.add_subject }}
|
||||
<input type="submit" name="add_subject_submit" value="Add Subject" id="submit_subject"></p>
|
||||
{% endcomment %}
|
||||
<p><b>Cover Image</b>: {{ form.cover_image.errors }}{{ form.cover_image }}{{ form.cover_image.help_text }}<br />
|
||||
(<i>Enter a link to an image, ideally 120px wide. You can't upload an image through this form at this time. If you have a cover image file and you're not sure how to put it online, email us and we can upload it for you.</I>)</p>
|
||||
<p><b>Cover Image</b>: <br />
|
||||
{% if edition.cover_image %}
|
||||
<img src="{{edition.cover_image}}" /><br />
|
||||
{% else %}
|
||||
[ no cover specified for this edition ]<br />
|
||||
{% endif %}
|
||||
{{ form.cover_image.errors }}{{ form.cover_image }}{{ form.cover_image.help_text }}
|
||||
(<i>Enter a URL for an image, ideally 120px wide. </i>)<br />
|
||||
OR...<br />
|
||||
|
||||
{{ form.coverfile.errors }}{{ form.coverfile }}{{ form.coverfile.help_text }}
|
||||
(<i>upload a cover image file, ideally 120px wide. </i>)<br />
|
||||
</p>
|
||||
{% if request.user.is_staff %}
|
||||
<p><b>Is this the unglued edition?</b> {{ form.unglued }}</p>
|
||||
{% endif %}
|
||||
|
|
|
@ -495,7 +495,7 @@ def new_edition(request, work_id, edition_id, by=None):
|
|||
except models.Author.DoesNotExist:
|
||||
author=models.Author.objects.create(name=new_author_name)
|
||||
edition.new_author_names.append(new_author_name)
|
||||
form = EditionForm(instance=edition, data=request.POST)
|
||||
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
|
||||
elif request.POST.has_key('add_subject_submit'):
|
||||
new_subject = request.POST['add_subject'].strip()
|
||||
try:
|
||||
|
@ -503,9 +503,9 @@ def new_edition(request, work_id, edition_id, by=None):
|
|||
except models.Subject.DoesNotExist:
|
||||
author=models.Subject.objects.create(name=new_subject)
|
||||
edition.new_subjects.append(new_subject)
|
||||
form = EditionForm(instance=edition, data=request.POST)
|
||||
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
|
||||
else:
|
||||
form = EditionForm(instance=edition, data=request.POST)
|
||||
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
if not work:
|
||||
|
@ -545,6 +545,16 @@ def new_edition(request, work_id, edition_id, by=None):
|
|||
subject=models.Subject.objects.create(name=subject_name)
|
||||
subject.works.add(work)
|
||||
work_url = reverse('work', kwargs={'work_id': edition.work.id})
|
||||
cover_file=form.cleaned_data.get("coverfile",None)
|
||||
if cover_file:
|
||||
# save it
|
||||
cover_file_name= '/Users/%s/covers/%s/%s' % ( request.user.username, edition.pk, cover_file.name)
|
||||
file = default_storage.open(cover_file_name, 'w')
|
||||
file.write(cover_file.read())
|
||||
file.close()
|
||||
#and put its url into cover_image
|
||||
edition.cover_image = default_storage.url(cover_file_name)
|
||||
edition.save()
|
||||
return HttpResponseRedirect(work_url)
|
||||
else:
|
||||
form = EditionForm(instance=edition, initial={
|
||||
|
|
Loading…
Reference in New Issue