Merge pull request #691 from Gluejar/edit-editions

Edit editions
pull/43/head
eshellman 2017-08-16 16:24:44 -04:00 committed by GitHub
commit 11f06226a7
7 changed files with 55 additions and 20 deletions

View File

@ -856,9 +856,22 @@ class BasePandataLoader(object):
if not work:
work = models.Work.objects.create(title=metadata.title, language=metadata.language)
if not edition:
edition = models.Edition.objects.create(title=metadata.title, work=work)
if metadata.edition_note:
(note, created) = models.EditionNote.objects.get_or_create(note=metadata.edition_note)
else:
note = None
edition = models.Edition.objects.create(
title=metadata.title,
work=work,
note=note,
)
for (identifier, id_code, value) in new_ids:
models.Identifier.set(type=id_code, value=value, edition=edition if id_code not in WORK_IDENTIFIERS else None, work=work)
models.Identifier.set(
type=id_code,
value=value,
edition=edition if id_code not in WORK_IDENTIFIERS else None,
work=work,
)
if metadata.publisher: #always believe yaml
edition.set_publisher(metadata.publisher)
if metadata.publication_date: #always believe yaml
@ -866,7 +879,7 @@ class BasePandataLoader(object):
if metadata.description and len(metadata.description) > len(work.description):
#be careful about overwriting the work description
work.description = metadata.description
if metadata.creator: #always believe yaml
if metadata.creator and not edition.authors.count():
edition.authors.clear()
for key in metadata.creator.keys():
creators = metadata.creator[key]

17
core/links.py Normal file
View File

@ -0,0 +1,17 @@
ID_URLS = {
'goog': u'https://books.google.com/books?id={}',
'olwk': u'https://openlibrary.org{}',
'gdrd': u'https://www.goodreads.com/book/show/{}',
'ltwk': u'https://librarything.com/work/{}',
'oclc': u'https://www.worldcat.org/oclc/{}',
'doi': u'https://doi.org/{}',
'gtbg': u'https://gutenberg.org/ebooks/{}',
'glue': u'https://unglue.it/work/{}',
}
def id_url(id_type, id_value):
url_string = ID_URLS.get(id_type, None)
if url_string and id_value:
return url_string.format(id_value)
else:
return ''

View File

@ -99,14 +99,15 @@ class BaseScraper(object):
if value:
self.identifiers['doi'] = value
isbns = {}
label_map = {'epub': 'EPUB', 'mobi': 'Mobi', 'paper':
'Paperback', 'pdf': 'PDF', 'hard':'Hardback'}
label_map = {'epub': 'EPUB', 'mobi': 'Mobi',
'paper': 'Paperback', 'pdf': 'PDF', 'hard':'Hardback'}
for key in label_map.keys():
isbn_key = 'isbn_{}'.format(key)
value = self.check_metas(['citation_isbn'], type=label_map[key])
value = identifier_cleaner('isbn')(value)
if value:
isbns[isbn_key] = value
self.identifiers['isbn_{}'] = value
ed_list = []
if len(isbns):
@ -114,7 +115,7 @@ class BaseScraper(object):
for key in isbns.keys():
isbn_type = key.split('_')[-1]
ed_list.append({
'edition': isbn_type,
'edition_note': isbn_type,
'edition_identifiers': {'isbn': isbns[key]}
})
else:
@ -124,7 +125,7 @@ class BaseScraper(object):
isbn = identifier_cleaner('isbn')(isbn)
if isbn:
ed_list.append({
'edition': isbn,
'_edition': isbn,
'edition_identifiers': {'isbn': isbn}
})
if len(ed_list):

View File

@ -29,6 +29,7 @@ from questionnaire.models import Landing
from regluit.core import mobi
import regluit.core.cc as cc
from regluit.core.epub import test_epub
from regluit.core.links import id_url
from regluit.core.parameters import (
AGE_LEVEL_CHOICES,
@ -107,6 +108,9 @@ class Identifier(models.Model):
def label(self):
return ID_CHOICES_MAP.get(self.type, self.type)
def url(self):
return id_url(self.type, self.value)
class Work(models.Model):
created = models.DateTimeField(auto_now_add=True, db_index=True,)
@ -161,10 +165,7 @@ class Work(models.Model):
@property
def googlebooks_url(self):
if self.googlebooks_id:
return "https://books.google.com/books?id=%s" % self.googlebooks_id
else:
return ''
return id_url('goog', self.googlebooks_id)
@property
def goodreads_id(self):
@ -178,7 +179,7 @@ class Work(models.Model):
@property
def goodreads_url(self):
return "https://www.goodreads.com/book/show/%s" % self.goodreads_id
return id_url('gdrd', self.goodreads_id)
@property
def librarything_id(self):
@ -186,7 +187,7 @@ class Work(models.Model):
@property
def librarything_url(self):
return "https://www.librarything.com/work/%s" % self.librarything_id
return id_url('ltwk', self.librarything_id)
@property
def openlibrary_id(self):
@ -194,8 +195,8 @@ class Work(models.Model):
@property
def openlibrary_url(self):
return "https://openlibrary.org" + self.openlibrary_id
return id_url('olwk', self.openlibrary_id)
def cover_filetype(self):
if self.uses_google_cover():
return 'jpeg'

View File

@ -3,7 +3,7 @@
<ul>
{% for ebook in work.ebooks_all %}
<li>
<a href="{{ ebook.url }}">{{ ebook.format }}</a>, created {{ ebook.created }}{% if ebook.user %},
<a href="{{ ebook.url }}">{{ ebook.format }}, {{ ebook.rights }}</a>, created {{ ebook.created }}{% if ebook.user %},
by <a href="{% url 'supporter' ebook.user.id %}">{{ ebook.user }}</a>{% endif %}.
{% if ebook.filesize %}{{ ebook.filesize }}{% else %}??{% endif %}B
{% if ebook.version_label %}{{ ebook.version }}{% endif %}

View File

@ -152,7 +152,7 @@ ul.fancytree-container {
<p><b>For the Work:</b></p>
<ul class="bullets">
{% for ident in edition.work.work_ids %}
<li><b>{{ ident.label }}</b>: {{ ident.value }}</li>
<li><b>{{ ident.label }}</b>: {% if ident.url %}<a href='{{ ident.url }}'>{{ ident.value }}</a>{% else %}{{ ident.value }}{% endif %}</li>
{% endfor %}
</ul>
{% endif %}
@ -160,13 +160,14 @@ ul.fancytree-container {
<p><b>For the Edition:</b></p>
<ul class="bullets">
{% for ident in edition.identifiers.all %}
<li><b>{{ ident.label }}</b>: {{ ident.value }}</li>
<li><b>{{ ident.label }}</b>: {% if ident.url %}<a href='{{ ident.url }}'>{{ ident.value }}</a>{% else %}{{ ident.value }}{% endif %}</li>
{% endfor %}
</ul>
{% endif %}
<p> Add/Change an Identifier (Enter 'delete' to remove it). </p>
{{ form.id_value.errors }}
{{ identform.as_p }}
{{ identform.id_type }}
{{ identform.id_value}}
<p><b>Description</b>: <br />
{{ form.description.errors }}{{ form.description }}<br />
(<i>{% if work.last_campaign %}

View File

@ -117,7 +117,9 @@
</li>
<li>{{ ebookfiles.days7.count }} have been added in the past 7 days.{% if request.user.is_staff %}
<ul class="terms">{% for ebook_file in ebookfiles.days7 %}
<li>{{ebook_file.edition.work.title}}: <a href="{{ebook_file.file.url}}">{{ebook_file.file}}</a> created {{ebook_file.created}}</li>
<li>{{ebook_file.edition.work.title}}: <a href="{{ebook_file.file.url}}">{{ebook_file.file}}</a> created {{ebook_file.created}} by {{ebook_file.ebook.user}}<br/>
({% if not ebook_file.ebook.active %}in{% endif %}active) <a href="{% url 'new_edition' ebook_file.edition.work.id ebook_file.edition.id %}">edit</a>
</li>
{% endfor %}</ul>{% endif %}
</li>