From 91ae62e757dd4ccffc8e769abd2946dc47a43284 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 4 Sep 2017 14:28:47 -0400 Subject: [PATCH 1/7] fix onix feed for work --- api/onix.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/onix.py b/api/onix.py index 1aba6b76..8b84c1fc 100644 --- a/api/onix.py +++ b/api/onix.py @@ -33,7 +33,9 @@ def onix_feed_for_work(work): feed = etree.fromstring(feed_xml) feed.append(header(work)) for edition in models.Edition.objects.filter(work=work,ebooks__isnull=False).distinct(): - feed.append(product(edition)) + edition_prod = product(edition) + if edition_prod: + feed.append(product(edition)) return etree.tostring(feed, pretty_print=True) def header(facet=None): From 5bbeb45053b6f39424368910f2888c3f907438f6 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 4 Sep 2017 16:10:24 -0400 Subject: [PATCH 2/7] improve merge_works work_relations were not being updated --- core/bookloader.py | 23 +++++++++++++++-------- core/loaders/doab.py | 4 ++-- core/loaders/utils.py | 4 +--- frontend/views/__init__.py | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/core/bookloader.py b/core/bookloader.py index 7868007b..c45fe541 100755 --- a/core/bookloader.py +++ b/core/bookloader.py @@ -413,7 +413,6 @@ def relate_isbn(isbn, cluster_size=1): elif related_edition.work.id != edition.work.id: logger.debug("merge_works path 1 %s %s", edition.work.id, related_edition.work.id ) merge_works(related_edition.work, edition.work) - if related_edition.work.editions.count()>cluster_size: return related_edition.work return edition.work @@ -452,7 +451,7 @@ def add_related(isbn): related_edition.save() elif related_edition.work.id != work.id: logger.debug("merge_works path 1 %s %s", work.id, related_edition.work.id ) - merge_works(work, related_edition.work) + work = merge_works(work, related_edition.work) else: if other_editions.has_key(related_language): other_editions[related_language].append(related_edition) @@ -469,12 +468,15 @@ def add_related(isbn): works_to_merge = set([ed.work for ed in lang_group[1:]]) - set([lang_edition.work]) for w in works_to_merge: logger.debug("merge_works path 2 %s %s", lang_edition.work.id, w.id ) - merge_works(lang_edition.work, w) - models.WorkRelation.objects.get_or_create(to_work=lang_edition.work, from_work=work, relation='translation') + merged_work = merge_works(lang_edition.work, w) + models.WorkRelation.objects.get_or_create( + to_work=lang_group[0].work, + from_work=work, + relation='translation' + ) return new_editions - def thingisbn(isbn): """given an ISBN return a list of related edition ISBNs, according to Library Thing. (takes isbn_10 or isbn_13, returns isbn_10, except for 979 isbns, which come back as isbn_13') @@ -492,7 +494,7 @@ def merge_works(w1, w2, user=None): logger.info("merging work %s into %s", w2.id, w1.id) # don't merge if the works are the same or at least one of the works has no id (for example, when w2 has already been deleted) if w1 is None or w2 is None or w1.id == w2.id or w1.id is None or w2.id is None: - return + return w1 if w2.selected_edition != None and w1.selected_edition == None: #the merge should be reversed temp = w1 @@ -546,9 +548,14 @@ def merge_works(w1, w2, user=None): for subject in w2.subjects.all(): if subject not in w1.subjects.all(): w1.subjects.add(subject) - - + for work_relation in w2.works_related_to.all(): + work_relation.to_work = w1 + work_relation.save() + for work_relation in w2.works_related_from.all(): + work_relation.from_work = w1 + work_relation.save() w2.delete() + return w1 def detach_edition(e): """will detach edition from its work, creating a new stub work. if remerge=true, will see if there's another work to attach to diff --git a/core/loaders/doab.py b/core/loaders/doab.py index 6127d0c0..3bf70bfd 100644 --- a/core/loaders/doab.py +++ b/core/loaders/doab.py @@ -130,9 +130,9 @@ def add_all_isbns(isbns, work, language=None, title=None): first_edition = first_edition if first_edition else edition if work and (edition.work.id != work.id): if work.created < edition.work.created: - merge_works(work, edition.work) + work = merge_works(work, edition.work) else: - merge_works(edition.work, work) + work = merge_works(edition.work, work) else: work = edition.work return first_edition diff --git a/core/loaders/utils.py b/core/loaders/utils.py index 68607d5f..1357bbd2 100644 --- a/core/loaders/utils.py +++ b/core/loaders/utils.py @@ -220,9 +220,7 @@ def load_from_books(books): for isbn in isbns: edition = add_by_isbn_from_google(isbn, work=work) if edition and edition.work != work: - merge_works(work, edition.work) - work = work if work.pk is not None else edition.work - edition.work=work # because integrity errors if not + work = merge_works(work, edition.work) if not edition: edition= Edition(title=title, work=work) edition.save() diff --git a/frontend/views/__init__.py b/frontend/views/__init__.py index 8687c93a..2d166afc 100755 --- a/frontend/views/__init__.py +++ b/frontend/views/__init__.py @@ -968,7 +968,7 @@ class MergeView(FormView): context = self.get_context_data() if self.request.POST.has_key('confirm_merge_works'): context['old_work_id'] = other_work.id - merge_works(self.work, other_work, self.request.user) + self.work = merge_works(self.work, other_work, self.request.user) context['merge_complete'] = True else: context['form'] = WorkForm(initial={'other_work':other_work}) From 302f70c2fb6d287bb9c0dc97734efaf4f3ca96f5 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 4 Sep 2017 16:10:55 -0400 Subject: [PATCH 3/7] bad variable reference --- core/validation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/validation.py b/core/validation.py index 3bba30b1..68ecbf66 100644 --- a/core/validation.py +++ b/core/validation.py @@ -43,7 +43,7 @@ def isbn_cleaner(value): if value == 'delete': return value if not value: - raise forms.ValidationError('no identifier value found') + raise ValidationError('no identifier value found') elif value == 'delete': return value isbn=ISBN(value) From ef90e901f1a5de41256a7d9bcb5b5e2fafef70b6 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 4 Sep 2017 16:52:06 -0400 Subject: [PATCH 4/7] add to bisac --- bisac/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bisac/__init__.py b/bisac/__init__.py index 08e027a4..554feb6d 100644 --- a/bisac/__init__.py +++ b/bisac/__init__.py @@ -23123,5 +23123,11 @@ bisac= { "pref_label": "Political Science / Terrorism", "notation": "POL037000", "alt_label": [] - } + }, + "History / Europe / Greece": { + "related": [], + "pref_label": "History / Europe / Greece", + "notation": "HIS042000", + "alt_label": [] + }, } \ No newline at end of file From d891a61bcd97b27f73a0c5a3afa3aee85be56d2f Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 4 Sep 2017 17:10:23 -0400 Subject: [PATCH 5/7] uniform edition cover images --- frontend/templates/edit_edition.html | 8 +++----- frontend/templates/edition_display.html | 8 +++----- frontend/templates/work.html | 2 +- static/css/campaign2.css | 2 +- static/css/manage_campaign.css | 2 +- static/less/book_detail.less | 2 +- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/frontend/templates/edit_edition.html b/frontend/templates/edit_edition.html index 940a18f2..7d4ae3fa 100644 --- a/frontend/templates/edit_edition.html +++ b/frontend/templates/edit_edition.html @@ -204,11 +204,9 @@ ul.fancytree-container {

Cover Image:
- {% if edition.cover_image %} -
- {% else %} - [ no cover specified for this edition ]
- {% endif %} +

+ +
{{ form.cover_image.errors }}{{ form.cover_image }}{{ form.cover_image.help_text }} (Enter a URL for an image, at least 300 px wide. The image will be scaled to the proportions of a 6x9 cover. )
OR...
diff --git a/frontend/templates/edition_display.html b/frontend/templates/edition_display.html index bb5a94cf..c3c4eea4 100644 --- a/frontend/templates/edition_display.html +++ b/frontend/templates/edition_display.html @@ -1,10 +1,8 @@
- {% if edition.googlebooks_id %} -
- edition cover -
- {% endif %} +
+ edition cover +