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 @@
- + {% 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 @@© {{ campaign.work.preferred_edition.publication_date }} by {{ campaign.work.author }}
+© {{ campaign.work.preferred_edition.publication_date }} by {{ campaign.work.authors_short }}
ISBN: {{ campaign.work.preferred_edition.isbn_13 }} .
URI: https://unglue.it/work/{{ campaign.work.id }}/ (this work).
diff --git a/frontend/templates/manage_campaign.html b/frontend/templates/manage_campaign.html index 03b4db16..e830e9a5 100644 --- a/frontend/templates/manage_campaign.html +++ b/frontend/templates/manage_campaign.html @@ -72,7 +72,7 @@ Please fix the following before launching your campaign: