fixed issues with null pubdates

pull/1/head
eric 2012-01-16 23:28:34 -05:00
parent 5dea6b7fea
commit c3dcd3d294
6 changed files with 15 additions and 4 deletions

View File

@ -406,6 +406,13 @@ class Work(models.Model):
except IndexError:
return ''
@property
def publication_date(self):
for edition in Edition.objects.filter(work=self):
if edition.publication_date:
return edition.publication_date
return ''
def __unicode__(self):
return self.title

View File

@ -39,6 +39,7 @@ class BookLoaderTests(TestCase):
# work
self.assertTrue(edition.work)
def test_double_add(self):
bookloader.add_by_isbn('0441012035')
@ -75,6 +76,9 @@ class BookLoaderTests(TestCase):
edition = tasks.populate_edition.run(edition)
self.assertTrue(edition.work.editions.all().count() > 20)
self.assertTrue(edition.work.subjects.all().count() > 10)
self.assertTrue(edition.work.publication_date)
edition.publication_date = None
self.assertTrue(edition.work.publication_date)
def test_merge_works(self):
# add two editions and see that there are two stub works

View File

@ -23,7 +23,7 @@ Please fix the following before launching your campaign:
<div class="book-detail-info">
<h2 class="book-name">Title: <a href="{% url work campaign.work.id %}">{{ campaign.work.title }}</a></h2>
<h3 class="book-author">Authors: {{ campaign.work.author }}</h3>
<h3 class="book-year">Published: {{ campaign.work.editions.all.0.publication_date }}</h3>
<h3 class="book-year">Published: {{ campaign.work.publication_date }}</h3>
<h3 class="book-author">Language: {{ campaign.work.editions.all.0.language }}</h3>
<p>Target Price: {{ campaign.pretarget }}</p>
<p>End Date: {{ campaign.predeadline }}</p>

View File

@ -18,7 +18,7 @@
<div class="book-detail-info">
<h2 class="book-name">{{ work.title }}</h2>
<h3 class="book-author">{{ work.author }}</h3>
<h3 class="book-year">{{ work.editions.all.0.publication_date }}</h3>
<h3 class="book-year">{{ work.publication_date }}</h3>
<div class="find-book">
<label>Find it here</label>
<!-- todo: these should be a real thing -->

View File

@ -8,7 +8,7 @@
<div class="book-detail-info">
<h2 class="book-name">Title: {{ work.title }}</h2>
<h3 class="book-author">Authors: {{ work.author }}</h3>
<h3 class="book-year">Published: {{ work.editions.all.0.publication_date }}</h3>
<h3 class="book-year">Published: {{ work.publication_date }}</h3>
<h3 class="book-author">Language: {{ work.editions.all.0.language }}</h3>
</div>
<form action="#">

View File

@ -97,7 +97,7 @@ def work(request, work_id, action='display'):
except:
pledged = None
try:
pubdate = work.editions.all()[0].publication_date[:4]
pubdate = work.publication_date[:4]
except IndexError:
pubdate = 'unknown'
if not request.user.is_anonymous():