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()
|
||||
if len(campaigns):
|
||||
c = campaigns[0]
|
||||
isbn = c.work.editions.all()[0].isbn_13
|
||||
try:
|
||||
isbn = c.work.editions.all()[0].isbn_13
|
||||
except IndexError:
|
||||
isbn = ''
|
||||
context["campaign"] = campaigns[0]
|
||||
context["campaign_isbn"] = isbn
|
||||
|
||||
|
|
|
@ -224,7 +224,10 @@ class Work(models.Model):
|
|||
@property
|
||||
def googlebooks_id(self):
|
||||
# may want to denormalize this at some point to avoid an extra query
|
||||
return self.editions.all()[0].googlebooks_id
|
||||
try:
|
||||
return self.editions.all()[0].googlebooks_id
|
||||
except IndexError:
|
||||
return ''
|
||||
|
||||
@property
|
||||
def googlebooks_url(self):
|
||||
|
@ -248,10 +251,16 @@ class Work(models.Model):
|
|||
return "http://openlibrary.org" + self.openlibrary_id
|
||||
|
||||
def cover_image_small(self):
|
||||
return self.editions.all()[0].cover_image_small()
|
||||
try:
|
||||
return self.editions.all()[0].cover_image_small()
|
||||
except IndexError:
|
||||
return "/static/images/generic_cover_larger.png"
|
||||
|
||||
def cover_image_thumbnail(self):
|
||||
return self.editions.all()[0].cover_image_thumbnail()
|
||||
try:
|
||||
return self.editions.all()[0].cover_image_thumbnail()
|
||||
except IndexError:
|
||||
return "/static/images/generic_cover_larger.png"
|
||||
|
||||
def author(self):
|
||||
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)
|
||||
editions = work.editions.all().order_by('-publication_date')
|
||||
campaign = work.last_campaign()
|
||||
pubdate = work.editions.all()[0].publication_date[:4]
|
||||
|
||||
try:
|
||||
pubdate = work.editions.all()[0].publication_date[:4]
|
||||
except IndexError:
|
||||
pubdate = 'unknown'
|
||||
if not request.user.is_anonymous():
|
||||
claimform = UserClaimForm( request.user, data={'work':work_id, 'user': request.user.id})
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue