From 3f80d24424537f0dc7f110b5d0f6c65eed2d5952 Mon Sep 17 00:00:00 2001
From: eric
Authors:
- {% if edition.authors or edition.new_author_names %}
+ {% if edition.pk and edition.authors or edition.new_author_names %}
Subjects:
Title and ISBN 13 are required; the rest is optional, though a cover image link is strongly recommended.
{% if edition.pk and edition.authors %}
{% for author in edition.authors.all %}
From 075219ace24977e4e34d68b2b0a9b6e21d08d70d Mon Sep 17 00:00:00 2001
From: eric
- {% if edition.work.subjects %}
+ {% if edition.work.pk and edition.work.subjects %}
{% for subject in edition.work.subjects.all %}
Cover Image: {{ form.cover_image.errors }}{{ form.cover_image }}{{ form.cover_image.help_text }}
- (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.)
Cover Image:
+ {% if edition.cover_image %}
+
+ {% else %}
+ [ no cover specified for this edition ]
+ {% endif %}
+ {{ form.cover_image.errors }}{{ form.cover_image }}{{ form.cover_image.help_text }}
+ (Enter a URL for an image, ideally 120px wide. )
+ OR...
+
+ {{ form.coverfile.errors }}{{ form.coverfile }}{{ form.coverfile.help_text }}
+ (upload a cover image file, ideally 120px wide. )
+
Is this the unglued edition? {{ form.unglued }}
{% endif %} diff --git a/frontend/views.py b/frontend/views.py index 309bcaad..1a0beabe 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -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 = 'https://%s.s3.amazonaws.com%s' % (settings.AWS_STORAGE_BUCKET_NAME , cover_file_name) + edition.save() return HttpResponseRedirect(work_url) else: form = EditionForm(instance=edition, initial={ From b5eccac2475d7ef6aa1b8252cd4f155eff3bc6cf Mon Sep 17 00:00:00 2001 From: Raymond Yee