catch IndexErrors to fix HermanCain bug; there is a work with zero editions
parent
c2789350d0
commit
9d6066c929
|
@ -104,7 +104,10 @@ class ApiHelpView(TemplateView):
|
||||||
campaigns = models.Campaign.objects.all()
|
campaigns = models.Campaign.objects.all()
|
||||||
if len(campaigns):
|
if len(campaigns):
|
||||||
c = campaigns[0]
|
c = campaigns[0]
|
||||||
|
try:
|
||||||
isbn = c.work.editions.all()[0].isbn_13
|
isbn = c.work.editions.all()[0].isbn_13
|
||||||
|
except IndexError:
|
||||||
|
isbn = ''
|
||||||
context["campaign"] = campaigns[0]
|
context["campaign"] = campaigns[0]
|
||||||
context["campaign_isbn"] = isbn
|
context["campaign_isbn"] = isbn
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,10 @@ class Work(models.Model):
|
||||||
@property
|
@property
|
||||||
def googlebooks_id(self):
|
def googlebooks_id(self):
|
||||||
# may want to denormalize this at some point to avoid an extra query
|
# may want to denormalize this at some point to avoid an extra query
|
||||||
|
try:
|
||||||
return self.editions.all()[0].googlebooks_id
|
return self.editions.all()[0].googlebooks_id
|
||||||
|
except IndexError:
|
||||||
|
return ''
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def googlebooks_url(self):
|
def googlebooks_url(self):
|
||||||
|
@ -248,10 +251,16 @@ class Work(models.Model):
|
||||||
return "http://openlibrary.org" + self.openlibrary_id
|
return "http://openlibrary.org" + self.openlibrary_id
|
||||||
|
|
||||||
def cover_image_small(self):
|
def cover_image_small(self):
|
||||||
|
try:
|
||||||
return self.editions.all()[0].cover_image_small()
|
return self.editions.all()[0].cover_image_small()
|
||||||
|
except IndexError:
|
||||||
|
return "/static/images/generic_cover_larger.png"
|
||||||
|
|
||||||
def cover_image_thumbnail(self):
|
def cover_image_thumbnail(self):
|
||||||
|
try:
|
||||||
return self.editions.all()[0].cover_image_thumbnail()
|
return self.editions.all()[0].cover_image_thumbnail()
|
||||||
|
except IndexError:
|
||||||
|
return "/static/images/generic_cover_larger.png"
|
||||||
|
|
||||||
def author(self):
|
def author(self):
|
||||||
authors = list(Author.objects.filter(editions__work=self).all())
|
authors = list(Author.objects.filter(editions__work=self).all())
|
||||||
|
|
|
@ -80,8 +80,10 @@ def work(request, work_id, action='display'):
|
||||||
work = get_object_or_404(models.Work, id=work_id)
|
work = get_object_or_404(models.Work, id=work_id)
|
||||||
editions = work.editions.all().order_by('-publication_date')
|
editions = work.editions.all().order_by('-publication_date')
|
||||||
campaign = work.last_campaign()
|
campaign = work.last_campaign()
|
||||||
|
try:
|
||||||
pubdate = work.editions.all()[0].publication_date[:4]
|
pubdate = work.editions.all()[0].publication_date[:4]
|
||||||
|
except IndexError:
|
||||||
|
pubdate = 'unknown'
|
||||||
if not request.user.is_anonymous():
|
if not request.user.is_anonymous():
|
||||||
claimform = UserClaimForm( request.user, data={'work':work_id, 'user': request.user.id})
|
claimform = UserClaimForm( request.user, data={'work':work_id, 'user': request.user.id})
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue