commit
40cdd1b141
|
@ -1262,8 +1262,13 @@ class Work(models.Model):
|
||||||
self.save()
|
self.save()
|
||||||
return self.selected_edition
|
return self.selected_edition
|
||||||
except IndexError:
|
except IndexError:
|
||||||
#should only happen if there are no editions for the work
|
#should only happen if there are no editions for the work,
|
||||||
return None
|
#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):
|
def last_campaign_status(self):
|
||||||
campaign = self.last_campaign()
|
campaign = self.last_campaign()
|
||||||
|
|
|
@ -788,6 +788,20 @@ class SafeGetWorkTest(TestCase):
|
||||||
work = safe_get_work(w2_id)
|
work = safe_get_work(w2_id)
|
||||||
self.assertEqual(work, w1)
|
self.assertEqual(work, w1)
|
||||||
self.assertRaises(Http404, safe_get_work, 3)
|
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):
|
class DownloadPageTest(TestCase):
|
||||||
def test_download_page(self):
|
def test_download_page(self):
|
||||||
|
|
Loading…
Reference in New Issue