Fix edition editing, add other identifiers
parent
d977fd6338
commit
3c61e292d9
|
@ -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 UserProfile, RightsHolder, Claim, Campaign, Premium, Ebook, Edition, PledgeExtra, Work, Press
|
||||||
from regluit.core.models import TWITTER, FACEBOOK, GRAVATAR
|
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
|
from regluit.utils.localdatetime import now
|
||||||
|
|
||||||
|
@ -27,10 +27,17 @@ logger = logging.getLogger(__name__)
|
||||||
class EditionForm(forms.ModelForm):
|
class EditionForm(forms.ModelForm):
|
||||||
add_author = forms.CharField(max_length=500, required=False)
|
add_author = forms.CharField(max_length=500, required=False)
|
||||||
add_subject = forms.CharField(max_length=200, 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"),
|
label=_("ISBN"),
|
||||||
max_length=13,
|
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,
|
required = True,
|
||||||
help_text = _("13 digits, no dash."),
|
help_text = _("13 digits, no dash."),
|
||||||
error_messages = {
|
error_messages = {
|
||||||
|
@ -38,9 +45,39 @@ class EditionForm(forms.ModelForm):
|
||||||
'required': _("Yes, we need an ISBN."),
|
'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"),
|
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,
|
required = False,
|
||||||
help_text = _("8 or more digits."),
|
help_text = _("8 or more digits."),
|
||||||
error_messages = {
|
error_messages = {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/ui-lightness/jquery-ui.css" type="text/css" media="screen">
|
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/ui-lightness/jquery-ui.css" type="text/css" media="screen">
|
||||||
{{ form.media.css }}
|
{{ form.media.css }}
|
||||||
<script type="text/javascript" src="{{ jquery_ui_home }}" ></script>
|
<script type="text/javascript" src="{{ jquery_ui_home }}" ></script>
|
||||||
|
|
||||||
{{ form.media.js }}
|
{{ form.media.js }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
{{ form.work }}
|
{{ form.work }}
|
||||||
<div>
|
<div>
|
||||||
<p><b>Title</b>: {{ form.title.errors }}{{ form.title }}</p>
|
<p><b>Title</b>: {{ form.title.errors }}{{ form.title }}</p>
|
||||||
|
<p><b>Publisher</b>: {{ form.publisher_name.errors }}{{ form.publisher_name }}</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Authors</b>:
|
<b>Authors</b>:
|
||||||
|
@ -43,9 +45,14 @@
|
||||||
<input type="submit" name="add_author_submit" value="Add Author" id="submit_author"></p>
|
<input type="submit" name="add_author_submit" value="Add Author" id="submit_author"></p>
|
||||||
|
|
||||||
<p><b>Language</b>: {{ form.language.errors }}{{ form.language }}</p>
|
<p><b>Language</b>: {{ form.language.errors }}{{ form.language }}</p>
|
||||||
|
<h4> Identifiers </h4>
|
||||||
<p><b>ISBN-13</b>: {{ form.isbn_13.errors }}{{ form.isbn_13 }}</p>
|
{% if id_msg %} <span class="errorlist">{{ id_msg }} </span>{% endif %}
|
||||||
<p><b>OCLC Number</b>: {{ form.oclcnum.errors }}{{ form.oclcnum }}</p>
|
<p> Enter 'delete' to remove the identifier. </p>
|
||||||
|
<p><b>ISBN-13</b>: {{ form.isbn.errors }}{{ form.isbn }}</p>
|
||||||
|
<p><b>OCLC Number</b>: {{ form.oclc.errors }}{{ form.oclc }}</p>
|
||||||
|
<p><b>Google Books ID</b>: {{ form.goog.errors }}{{ form.goog }}</p>
|
||||||
|
<p><b>GoodReads ID</b>: {{ form.gdrd.errors }}{{ form.gdrd }}</p>
|
||||||
|
<p><b>LibraryThing ID</b>: {{ form.thng.errors }}{{ form.thng }}</p>
|
||||||
|
|
||||||
<p><b>Description</b>: <br />
|
<p><b>Description</b>: <br />
|
||||||
{{ form.description.errors }}{{ form.description }}<br />
|
{{ form.description.errors }}{{ form.description }}<br />
|
||||||
|
|
|
@ -407,12 +407,20 @@ def new_edition(request, work_id, edition_id, by=None):
|
||||||
work.title=form.cleaned_data['title']
|
work.title=form.cleaned_data['title']
|
||||||
work.save()
|
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
|
id_msg=""
|
||||||
models.Identifier.set(type='isbn', value=form.cleaned_data['isbn_13'], edition=edition, work=work)
|
for id_type in ('isbn', 'oclc', 'goog', 'thng', 'gdrd'):
|
||||||
|
id_val = form.cleaned_data[id_type]
|
||||||
if form.cleaned_data['oclcnum']:
|
if id_val=='delete':
|
||||||
# note: this is very powerful.(same comment as for isbn) use with care!
|
edition.identifiers.filter(type=id_type).delete()
|
||||||
models.Identifier.set(type='oclc', value=form.cleaned_data['oclcnum'], edition=edition, work=work)
|
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:
|
for author_name in edition.new_author_names:
|
||||||
try:
|
try:
|
||||||
author= models.Author.objects.get(name=author_name)
|
author= models.Author.objects.get(name=author_name)
|
||||||
|
@ -430,14 +438,18 @@ def new_edition(request, work_id, edition_id, by=None):
|
||||||
else:
|
else:
|
||||||
form = EditionForm(instance=edition, initial={
|
form = EditionForm(instance=edition, initial={
|
||||||
'language':language,
|
'language':language,
|
||||||
'isbn_13':edition.isbn_13,
|
'publisher_name':edition.publisher_name,
|
||||||
'oclcnum':edition.oclc,
|
'isbn':edition.isbn_13,
|
||||||
|
'oclc':edition.oclc,
|
||||||
'description':description,
|
'description':description,
|
||||||
'title': title
|
'title': title,
|
||||||
|
'goog': edition.googlebooks_id,
|
||||||
|
'gdrd': edition.goodreads_id,
|
||||||
|
'thng': edition.librarything_id,
|
||||||
})
|
})
|
||||||
|
|
||||||
return render(request, 'new_edition.html', {
|
return render(request, 'new_edition.html', {
|
||||||
'form': form, 'edition': edition
|
'form': form, 'edition': edition,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue