From bc9f1d3cd3dcb31442c0d7db55e7df5edf87a8dc Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 27 Apr 2012 17:14:57 -0400 Subject: [PATCH] [fix #28759049] prefixing ebook contribution form not handled properly in view or form --- core/models.py | 2 +- frontend/forms.py | 4 ++-- frontend/templates/work.html | 12 ++++++------ frontend/views.py | 21 +++++++++++++-------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/core/models.py b/core/models.py index 85c96a8a..d27f26a5 100755 --- a/core/models.py +++ b/core/models.py @@ -621,7 +621,7 @@ class Ebook(models.Model): provider='Google Books' elif url.startswith('http://www.gutenberg.org/'): provider='Project Gutenberg' - elif url.startswith('http://www.archive.org/'): + elif url.startswith('http://www.archive.org/') or url.startswith('http://archive.org/'): provider='Internet Archive' elif url.startswith('http://hdl.handle.net/2027/') or url.startswith('http://babel.hathitrust.org/'): provider='Hathitrust' diff --git a/frontend/forms.py b/frontend/forms.py index 5d848330..18f4cea6 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -31,13 +31,13 @@ class EbookForm(forms.ModelForm): 'url': forms.TextInput(attrs={'size' : 60}), } def clean_provider(self): - new_provider= Ebook.infer_provider(self.data['url']) + new_provider= Ebook.infer_provider(self.data[self.prefix + '-url']) if not new_provider: raise forms.ValidationError(_("At this time, ebook URLs must point at Internet Archive, Wikisources, Hathitrust, Project Gutenberg, or Google Books.")) return new_provider def clean_url(self): - url = self.data["url"] + url = self.data[self.prefix + '-url'] try: Ebook.objects.get(url=url) except Ebook.DoesNotExist: diff --git a/frontend/templates/work.html b/frontend/templates/work.html index 048dc78a..18c46d4f 100644 --- a/frontend/templates/work.html +++ b/frontend/templates/work.html @@ -301,8 +301,8 @@ $j(document).ready(function(){ See this edition on Google Books {{work.last_campaign_status}} {% if edition.ebook_form %}{% ifnotequal status 'ACTIVE' %} -
more...
-
+ {% if edition.hide_details %}
more...
{% endif %} +
{% if edition.ebooks.count %}
eBooks for this Edition
{% for ebook in edition.ebooks.all %} @@ -312,10 +312,10 @@ $j(document).ready(function(){
Add an eBook for this Edition:
If you know that this edition is available as a public domain or Creative Commons ebook, you can enter the link here and "unglue" it. Right now, we're only accepting URLs that point to Internet Archive, Wikisources, Hathitrust, Project Gutenberg, or Google Books.
- {% csrf_token %}{{ edition.ebook_form.edition }}{{ edition.ebook_form.user }}{{ edition.ebook_form.provider }} - URL: {{ edition.ebook_form.url }}
- File Format: {{ edition.ebook_form.format }}    - License: {{ edition.ebook_form.rights }}
+ {% csrf_token %}{{ edition.ebook_form.edition.errors }}{{ edition.ebook_form.edition }}{{ edition.ebook_form.user.errors }}{{ edition.ebook_form.user }}{{ edition.ebook_form.provider.errors }}{{ edition.ebook_form.provider }} + {{ edition.ebook_form.url.errors }}URL: {{ edition.ebook_form.url }}
+ {{ edition.ebook_form.format.errors }}File Format: {{ edition.ebook_form.format }}    + {{ edition.ebook_form.rights.errors }}License: {{ edition.ebook_form.rights }}
diff --git a/frontend/views.py b/frontend/views.py index b5b44df0..c7b9c6df 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -121,12 +121,6 @@ def work(request, work_id, action='display'): if request.method == 'POST' and not request.user.is_anonymous(): activetab = '4' - ebook_form= EbookForm( data = request.POST) - if ebook_form.is_valid(): - ebook_form.save() - alert = 'Thanks for adding an ebook to unglue.it!' - else: - alert = ebook_form.errors else: alert='' try: @@ -151,8 +145,19 @@ def work(request, work_id, action='display'): if not request.user.is_anonymous(): claimform = UserClaimForm( request.user, data={'claim-work':work.pk, 'claim-user': request.user.id}, prefix = 'claim') for edition in editions: - #edition.ebook_form = EbookForm( data = {'user':request.user.id, 'edition':edition.pk }) - edition.ebook_form = EbookForm( instance= models.Ebook(user = request.user, edition = edition, provider = 'x' ), prefix = 'ebook_%d'%edition.id) + edition.hide_details = 1 + if request.method == 'POST' and not request.user.is_anonymous(): + if request.POST.has_key('ebook_%d-edition' % edition.id): + edition.ebook_form= EbookForm( data = request.POST, prefix = 'ebook_%d'%edition.id) + if edition.ebook_form.is_valid(): + edition.ebook_form.save() + alert = 'Thanks for adding an ebook to unglue.it!' + else: + edition.hide_details = 0 + alert = 'your submitted ebook had errors' + else: + #edition.ebook_form = EbookForm( data = {'user':request.user.id, 'edition':edition.pk }) + edition.ebook_form = EbookForm( instance= models.Ebook(user = request.user, edition = edition, provider = 'x' ), prefix = 'ebook_%d'%edition.id) else: claimform = None if campaign: