[fix #28759049] prefixing ebook contribution form not handled properly in view or form
parent
6dcefd157c
commit
bc9f1d3cd3
|
@ -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'
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -301,8 +301,8 @@ $j(document).ready(function(){
|
|||
See <a href="https://encrypted.google.com/books?id={{ edition.googlebooks_id }}">this edition on Google Books</a></div>
|
||||
</div>{{work.last_campaign_status}}
|
||||
{% if edition.ebook_form %}{% ifnotequal status 'ACTIVE' %}
|
||||
<div class="show_more_edition" >more...</div>
|
||||
<div class="more_edition">
|
||||
{% if edition.hide_details %}<div class="show_more_edition" >more...</div>{% endif %}
|
||||
<div {% if edition.hide_details %} class="more_edition" {% endif %}>
|
||||
{% if edition.ebooks.count %}
|
||||
<h5>eBooks for this Edition</h5>
|
||||
{% for ebook in edition.ebooks.all %}
|
||||
|
@ -312,10 +312,10 @@ $j(document).ready(function(){
|
|||
<h5>Add an eBook for this Edition:</h5>
|
||||
<span>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.</span>
|
||||
<form method="POST" action="#edition_{{edition.id}}">
|
||||
{% csrf_token %}{{ edition.ebook_form.edition }}{{ edition.ebook_form.user }}{{ edition.ebook_form.provider }}
|
||||
URL: {{ edition.ebook_form.url }}<br />
|
||||
File Format: {{ edition.ebook_form.format }}
|
||||
License: {{ edition.ebook_form.rights }}<br />
|
||||
{% 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 }}<span>URL: {{ edition.ebook_form.url }}</span><br />
|
||||
{{ edition.ebook_form.format.errors }}<span>File Format: {{ edition.ebook_form.format }}</span>
|
||||
{{ edition.ebook_form.rights.errors }}<span>License: {{ edition.ebook_form.rights }}</span><br />
|
||||
<input type="submit" name="add_ebook" value="add ebook" />
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue