fix occasional bug
parent
8d80be5248
commit
1833318c2d
|
@ -1261,7 +1261,12 @@ class Work(models.Model):
|
|||
self.save()
|
||||
return self.selected_edition
|
||||
except IndexError:
|
||||
#should only happen if there are no editions for the work
|
||||
#should only happen if there are no editions for the work,
|
||||
#which can happen when works are being merged
|
||||
try:
|
||||
return WasWork.objects.get(was=self.id).work.preferred_edition
|
||||
except WasWork.DoesNotExist:
|
||||
#should not happen
|
||||
return None
|
||||
|
||||
def last_campaign_status(self):
|
||||
|
|
|
@ -789,6 +789,20 @@ class SafeGetWorkTest(TestCase):
|
|||
self.assertEqual(work, w1)
|
||||
self.assertRaises(Http404, safe_get_work, 3)
|
||||
|
||||
class WorkTests(TestCase):
|
||||
def test_preferred_edition(self):
|
||||
w1 = models.Work.objects.create()
|
||||
w2 = models.Work.objects.create()
|
||||
ww = models.WasWork.objects.create(work=w1, was= w2.id)
|
||||
e1 = models.Edition.objects.create(work=w1)
|
||||
self.assertEqual(e1, w1.preferred_edition)
|
||||
e2 = models.Edition.objects.create(work=w1)
|
||||
w1.selected_edition=e2
|
||||
w1.save()
|
||||
self.assertEqual(e2, w1.preferred_edition)
|
||||
self.assertEqual(e2, w2.preferred_edition)
|
||||
|
||||
|
||||
class DownloadPageTest(TestCase):
|
||||
def test_download_page(self):
|
||||
w = models.Work()
|
||||
|
|
Loading…
Reference in New Issue