diff --git a/frontend/forms.py b/frontend/forms.py index e4be038e..5ea2a505 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -16,7 +16,7 @@ from selectable.forms import AutoCompleteSelectWidget,AutoCompleteSelectField from regluit.core.models import UserProfile, RightsHolder, Claim, Campaign, Premium, Ebook, Edition, PledgeExtra, Work, Press from regluit.core.models import TWITTER, FACEBOOK, GRAVATAR -from regluit.core.lookups import OwnerLookup, WorkLookup +from regluit.core.lookups import OwnerLookup, WorkLookup, PublisherNameLookup from regluit.utils.localdatetime import now @@ -27,10 +27,17 @@ logger = logging.getLogger(__name__) class EditionForm(forms.ModelForm): add_author = forms.CharField(max_length=500, required=False) add_subject = forms.CharField(max_length=200, required=False) - isbn_13 = forms.RegexField( + publisher_name = AutoCompleteSelectField( + PublisherNameLookup, + label='Publisher Name', + widget=AutoCompleteSelectWidget(PublisherNameLookup), + required=False, + ) + + isbn = forms.RegexField( label=_("ISBN"), max_length=13, - regex=r'^97[89]\d\d\d\d\d\d\d\d\d\d$', + regex=r'^(97[89]\d\d\d\d\d\d\d\d\d\d|delete)$', required = True, help_text = _("13 digits, no dash."), error_messages = { @@ -38,9 +45,39 @@ class EditionForm(forms.ModelForm): 'required': _("Yes, we need an ISBN."), } ) - oclcnum = forms.RegexField( + goog = forms.RegexField( + label=_("Google Books ID"), + max_length=12, + regex=r'^([a-zA-Z0-9\-_]{12}|delete)$', + required = False, + help_text = _("12 alphanumeric characters, dash or underscore, case sensitive."), + error_messages = { + 'invalid': _("This value must be 12 alphanumeric characters, dash or underscore."), + } + ) + gdrd = forms.RegexField( + label=_("GoodReads ID"), + max_length=8, + regex=r'^(\d+|delete)$', + required = False, + help_text = _("1-8 digits."), + error_messages = { + 'invalid': _("This value must be 1-8 digits."), + } + ) + thng = forms.RegexField( + label=_("LibraryThing ID"), + max_length=8, + regex=r'(^\d+|delete)$', + required = False, + help_text = _("1-8 digits."), + error_messages = { + 'invalid': _("This value must be 1-8 digits."), + } + ) + oclc = forms.RegexField( label=_("OCLCnum"), - regex=r'^\d\d\d\d\d\d\d\d\d*$', + regex=r'^(\d\d\d\d\d\d\d\d\d*|delete)$', required = False, help_text = _("8 or more digits."), error_messages = { diff --git a/frontend/templates/new_edition.html b/frontend/templates/new_edition.html index 5f580398..5d78710b 100644 --- a/frontend/templates/new_edition.html +++ b/frontend/templates/new_edition.html @@ -4,6 +4,7 @@ {{ form.media.css }} + {{ form.media.js }} {% endblock %} @@ -20,6 +21,7 @@ {{ form.work }}
Title: {{ form.title.errors }}{{ form.title }}
+Publisher: {{ form.publisher_name.errors }}{{ form.publisher_name }}
Authors: @@ -43,9 +45,14 @@
Language: {{ form.language.errors }}{{ form.language }}
- -ISBN-13: {{ form.isbn_13.errors }}{{ form.isbn_13 }}
-OCLC Number: {{ form.oclcnum.errors }}{{ form.oclcnum }}
+Enter 'delete' to remove the identifier.
+ISBN-13: {{ form.isbn.errors }}{{ form.isbn }}
+OCLC Number: {{ form.oclc.errors }}{{ form.oclc }}
+Google Books ID: {{ form.goog.errors }}{{ form.goog }}
+GoodReads ID: {{ form.gdrd.errors }}{{ form.gdrd }}
+LibraryThing ID: {{ form.thng.errors }}{{ form.thng }}
Description:
{{ form.description.errors }}{{ form.description }}
diff --git a/frontend/views.py b/frontend/views.py
index 79eaafef..09a594d3 100755
--- a/frontend/views.py
+++ b/frontend/views.py
@@ -407,12 +407,20 @@ def new_edition(request, work_id, edition_id, by=None):
work.title=form.cleaned_data['title']
work.save()
- # note: this is very powerful. it can steal an isbn from another edition/work, and it will wipe the changed isbn from the db
- models.Identifier.set(type='isbn', value=form.cleaned_data['isbn_13'], edition=edition, work=work)
-
- if form.cleaned_data['oclcnum']:
- # note: this is very powerful.(same comment as for isbn) use with care!
- models.Identifier.set(type='oclc', value=form.cleaned_data['oclcnum'], edition=edition, work=work)
+ id_msg=""
+ for id_type in ('isbn', 'oclc', 'goog', 'thng', 'gdrd'):
+ id_val = form.cleaned_data[id_type]
+ if id_val=='delete':
+ edition.identifiers.filter(type=id_type).delete()
+ elif id_val:
+ existing= models.Identifier.objects.filter(type=id_type, value=form.cleaned_data[id_type])
+ if existing.count() and existing[0].edition != edition:
+ return render(request, 'new_edition.html', {
+ 'form': form, 'edition': edition,
+ 'id_msg': "%s = %s already exists"%( id_type, id_val ),
+ })
+ else:
+ models.Identifier.set(type=id_type, value=id_val, edition=edition, work=work)
for author_name in edition.new_author_names:
try:
author= models.Author.objects.get(name=author_name)
@@ -430,14 +438,18 @@ def new_edition(request, work_id, edition_id, by=None):
else:
form = EditionForm(instance=edition, initial={
'language':language,
- 'isbn_13':edition.isbn_13,
- 'oclcnum':edition.oclc,
+ 'publisher_name':edition.publisher_name,
+ 'isbn':edition.isbn_13,
+ 'oclc':edition.oclc,
'description':description,
- 'title': title
+ 'title': title,
+ 'goog': edition.googlebooks_id,
+ 'gdrd': edition.goodreads_id,
+ 'thng': edition.librarything_id,
})
return render(request, 'new_edition.html', {
- 'form': form, 'edition': edition
+ 'form': form, 'edition': edition,
})