From e540bb7a56d614413118b71f65f754547927267f Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 17 Jan 2014 21:37:19 -0500 Subject: [PATCH] all authors now display had to harden the work model against works without editions to pass tests Lagos 2060 will need 1st author to change back added work.authors_short to work model and to search work mock model used work #415 as an example of a work with 3 authors --- core/models.py | 28 +++++++++++++++++-------- core/search.py | 8 ++++++- frontend/templates/book_panel.html | 4 ++-- frontend/templates/claim.html | 2 +- frontend/templates/front_matter.html | 2 +- frontend/templates/manage_campaign.html | 2 +- frontend/templates/pledge.html | 2 +- frontend/templates/purchase.html | 2 +- frontend/templates/rh_tools.html | 2 +- frontend/templates/rights_holders.html | 4 ++-- frontend/templates/work.html | 14 ++++++++++++- 11 files changed, 49 insertions(+), 21 deletions(-) diff --git a/core/models.py b/core/models.py index 5ad2ef2e..b655ea67 100755 --- a/core/models.py +++ b/core/models.py @@ -1066,7 +1066,7 @@ class Work(models.Model): def cover_image_thumbnail(self): try: - if self.preferred_edition.cover_image_thumbnail(): + if self.preferred_edition and self.preferred_edition.cover_image_thumbnail(): return self.preferred_edition.cover_image_thumbnail() except IndexError: pass @@ -1074,19 +1074,29 @@ class Work(models.Model): def authors(self): # assumes that they come out in the same order they go in! - return self.preferred_edition.authors.all() + if self.preferred_edition and self.preferred_edition.authors.all().count()>0: + return self.preferred_edition.authors.all() + for edition in self.editions.all(): + if edition.authors.all().count()>0: + return edition.authors.all() + return [] def author(self): # assumes that they come out in the same order they go in! if self.authors().count()>0: return self.authors()[0].name + return '' - # just in case that particular edition has no author - try: - return list(Author.objects.filter(editions__work=self).all()).authors[0].name - except: - return '' - + def authors_short(self): + # assumes that they come out in the same order they go in! + if self.authors().count()==1: + return self.authors()[0].name + elif self.authors().count()==2: + return "%s and %s" % (self.authors()[0].name, self.authors()[1].name) + elif self.authors().count()>2: + return "%s et al." % self.authors()[0].name + return '' + def last_campaign(self): # stash away the last campaign to prevent repeated lookups if hasattr(self, '_last_campaign_'): @@ -1102,7 +1112,7 @@ class Work(models.Model): if self.last_campaign(): if self.last_campaign().edition: return self.last_campaign().edition - return self.editions.all()[0] + return self.editions.all()[0] if self.editions.all().count() else None def last_campaign_status(self): campaign = self.last_campaign() diff --git a/core/search.py b/core/search.py index eaf1a274..8b626333 100644 --- a/core/search.py +++ b/core/search.py @@ -19,8 +19,14 @@ def gluejar_search(q, user_ip='69.243.24.29', page=1): 'googlebooks_id': item.get('id')} # TODO: allow multiple authors - if v.has_key('authors') and len(v['authors']) > 0: + if v.has_key('authors') and len(v['authors']) == 1 : + r['author'] = r['authors_short'] = v['authors'][0] + elif v.has_key('authors') and len(v['authors']) > 2: r['author'] = v['authors'][0] + r['authors_short'] = '%s et al.' % v['authors'][0] + elif v.has_key('authors') and len(v['authors']) == 2: + r['author'] = v['authors'][0] + r['authors_short'] = '%s and %s' % (v['authors'][0], v['authors'][1]) else: r['author'] = "" r['isbn_13'] = None diff --git a/frontend/templates/book_panel.html b/frontend/templates/book_panel.html index 99c65677..8b10f30f 100644 --- a/frontend/templates/book_panel.html +++ b/frontend/templates/book_panel.html @@ -5,7 +5,7 @@ {% with work.first_ebook as first_ebook %} {% with work.last_campaign.supporters as supporters %} {% with work.cover_image_thumbnail as thumbnail %} -{% with work.author as author %} +{% with work.authors_short as author %} {% with work.title as title %} {% with work.last_campaign as last_campaign %} {% with work.last_campaign.status as status %} @@ -192,7 +192,7 @@
{{ title }}
-
{{ author }}
+
{{ author }}
{% comment %}same logic as above{% endcomment %} diff --git a/frontend/templates/claim.html b/frontend/templates/claim.html index 10b46fd9..ba0953ed 100644 --- a/frontend/templates/claim.html +++ b/frontend/templates/claim.html @@ -8,7 +8,7 @@

Work being claimed

{% if active_claims.count %} diff --git a/frontend/templates/front_matter.html b/frontend/templates/front_matter.html index 2992499d..8aef5758 100644 --- a/frontend/templates/front_matter.html +++ b/frontend/templates/front_matter.html @@ -24,7 +24,7 @@