Merge pull request #18 from Gluejar/add_oclc
Add worldcat links and oclcnum editing [#32289887]pull/1/head
commit
77abb2d048
|
@ -409,6 +409,24 @@ class Identifier(models.Model):
|
|||
|
||||
class Meta:
|
||||
unique_together = ("type", "value")
|
||||
|
||||
@staticmethod
|
||||
def set(type=None, value=None, edition=None, work=None):
|
||||
# if there's already an id of this type for this work and edition, change it
|
||||
# if not, create it. if the id exists and points to something else, change it.
|
||||
identifier= Identifier.get_or_add(type=type, value=value, edition = edition, work=work)
|
||||
if identifier.work.id != work.id:
|
||||
identifier.work=work
|
||||
identifier.save()
|
||||
if identifier.edition and edition:
|
||||
if identifier.edition.id != edition.id:
|
||||
identifier.edition = edition
|
||||
identifier.save()
|
||||
others= Identifier.objects.filter(type=type, work=work, edition=edition).exclude(value=value)
|
||||
if others.count()>0:
|
||||
for other in others:
|
||||
other.delete()
|
||||
return identifier
|
||||
|
||||
@classmethod
|
||||
def get_or_add(klass, type='goog', value=None, edition=None, work=None):
|
||||
|
@ -609,6 +627,15 @@ class Work(models.Model):
|
|||
self.num_wishes = Wishes.objects.filter(work=self).count()
|
||||
self.save()
|
||||
|
||||
def first_oclc(self):
|
||||
preferred_id=self.preferred_edition.oclc
|
||||
if preferred_id:
|
||||
return preferred_id
|
||||
try:
|
||||
return self.identifiers.filter(type='oclc')[0].value
|
||||
except IndexError:
|
||||
return ''
|
||||
|
||||
def first_isbn_13(self):
|
||||
preferred_id=self.preferred_edition.isbn_13
|
||||
if preferred_id:
|
||||
|
|
|
@ -36,6 +36,15 @@ class EditionForm(forms.ModelForm):
|
|||
'required': _("Yes, we need an ISBN."),
|
||||
}
|
||||
)
|
||||
oclcnum = forms.RegexField(
|
||||
label=_("OCLCnum"),
|
||||
regex=r'^\d\d\d\d\d\d\d\d\d*$',
|
||||
required = False,
|
||||
help_text = _("8 or more digits."),
|
||||
error_messages = {
|
||||
'invalid': _("This value must be 8 or more digits."),
|
||||
}
|
||||
)
|
||||
language = forms.ChoiceField(choices=LANGUAGES)
|
||||
description = forms.CharField( required=False, widget= forms.Textarea(attrs={'cols': 80, 'rows': 2}))
|
||||
class Meta:
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
<p><b>Language</b>: {{ form.language.errors }}{{ form.language }}</p>
|
||||
|
||||
<p><b>ISBN-13</b>: {{ form.isbn_13.errors }}{{ form.isbn_13 }}</p>
|
||||
<p><b>OCLC Number</b>: {{ form.oclcnum.errors }}{{ form.oclcnum }}</p>
|
||||
|
||||
<p><b>Description</b>: <br />
|
||||
{{ form.description.errors }}{{ form.description }}<br />
|
||||
|
|
|
@ -153,6 +153,9 @@ $j(document).ready(function(){
|
|||
{% if work.googlebooks_id %}
|
||||
<a id="find-google" href="{{ work.googlebooks_url }}"><img src="/static/images/supporter_icons/googlebooks_square.png" title="Find on Google Books" alt="Find on Google Books" /></a>
|
||||
{% endif %}
|
||||
{% if work.first_oclc %}
|
||||
<a rel="nofollow" id="find-oclc" href="http://www.worldcat.org/oclc/{{ work.first_oclc }}"><img src="/static/images/supporter_icons/worldcat_square.png" title="Find on Worldcat" alt="Find on Worldcat" /></a>
|
||||
{% endif %}
|
||||
<a rel="nofollow" class="find-openlibrary" href="{% url work_openlibrary work_id %}"><img src="/static/images/supporter_icons/openlibrary_square.png" title="Find on OpenLibrary" alt="Find on OpenLibrary" /></a>
|
||||
{% if not request.user.is_anonymous %}
|
||||
{% if request.user.profile.goodreads_user_link %}
|
||||
|
|
|
@ -249,7 +249,7 @@ def work(request, work_id, action='display'):
|
|||
'claimstatus': claimstatus,
|
||||
'rights_holder_name': rights_holder_name,
|
||||
'countdown': countdown,
|
||||
})
|
||||
})
|
||||
|
||||
def new_edition(request, work_id, edition_id, by=None):
|
||||
if not request.user.is_authenticated() :
|
||||
|
@ -324,7 +324,13 @@ def new_edition(request, work_id, edition_id, by=None):
|
|||
work.description=form.cleaned_data['description']
|
||||
work.title=form.cleaned_data['title']
|
||||
work.save()
|
||||
models.Identifier.get_or_add(type='isbn', value=form.cleaned_data['isbn_13'], edition=edition, work=work)
|
||||
|
||||
# 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)
|
||||
for author_name in edition.new_author_names:
|
||||
try:
|
||||
author= models.Author.objects.get(name=author_name)
|
||||
|
@ -343,6 +349,7 @@ def new_edition(request, work_id, edition_id, by=None):
|
|||
form = EditionForm(instance=edition, initial={
|
||||
'language':language,
|
||||
'isbn_13':edition.isbn_13,
|
||||
'oclcnum':edition.oclc,
|
||||
'description':description,
|
||||
'title': title
|
||||
})
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
Loading…
Reference in New Issue