Skip to content

Commit

Permalink
Merge pull request mozilla#167 from lmorchard/include-nomination-in-a…
Browse files Browse the repository at this point in the history
…ward-detail

Include nomination in award detail when necessary
  • Loading branch information
lmorchard committed Mar 21, 2013
2 parents 7f3dd23 + 935caca commit 86f9e3c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
9 changes: 9 additions & 0 deletions badger/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,15 @@ def bake_obi_image(self, request=None):

return True

@property
def nomination(self):
"""Find the nomination behind this award, if any."""
# TODO: This should really be a foreign key relation, someday.
try:
return Nomination.objects.get(award=self)
except:
return None


class ProgressManager(models.Manager):
pass
Expand Down
58 changes: 58 additions & 0 deletions badger/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,64 @@ def test_awards_by_badge(self):
eq_(1, doc.find('.award .user:contains("%s")' % u.username)
.length)

def test_award_detail_includes_nomination(self):
"""Nomination should be included in award detail"""
creator = self._get_user(username="creator", email="creator@example.com")
awardee = self._get_user(username="awardee", email="awardee@example.com")
nominator = self._get_user(username="nominator", email="nominator@example.com")

b1 = Badge.objects.create(creator=creator, title="Badge to awarded")

ok_(not b1.is_awarded_to(awardee))

nomination = b1.nominate_for(nominator=nominator, nominee=awardee)
nomination.approve_by(creator)
nomination.accept(awardee)

ok_(b1.is_awarded_to(awardee))

award = Award.objects.get(badge=b1, user=awardee)

r = self.client.get(award.get_absolute_url(), follow=True)
eq_(200, r.status_code)

doc = pq(r.content)

nomination_el = doc.find('.award .nominated_by .username')
eq_(nomination_el.length, 1)
eq_(nomination_el.text(), str(nominator))

approved_el = doc.find('.award .nomination_approved_by .username')
eq_(approved_el.length, 1)
eq_(approved_el.text(), str(creator))

def test_award_detail_includes_nomination_autoapproved(self):
"""Auto-approved nomination should be indicated in award detail"""
creator = self._get_user(username="creator", email="creator@example.com")
awardee = self._get_user(username="awardee", email="awardee@example.com")
nominator = self._get_user(username="nominator", email="nominator@example.com")

b2 = Badge.objects.create(creator=creator, title="Badge to awarded 2")
b2.nominations_autoapproved = True
b2.save()

ok_(not b2.is_awarded_to(awardee))

nomination = b2.nominate_for(nominator=nominator, nominee=awardee)
nomination.accept(awardee)

ok_(b2.is_awarded_to(awardee))

award = Award.objects.get(badge=b2, user=awardee)

r = self.client.get(award.get_absolute_url(), follow=True)
eq_(200, r.status_code)

doc = pq(r.content)

approved_el = doc.find('.award .nomination_approved_by .autoapproved')
eq_(approved_el.length, 1)

def test_issue_award(self):
"""Badge creator can issue award to another user"""
SAMPLE_DESCRIPTION = u'This is a sample description'
Expand Down
21 changes: 17 additions & 4 deletions badger_example/templates/badger/includes/award_full.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@
{% if award.description %}
<dt>Explanation:</dt>
<dd class="description">{{ award.description }}</dd>
{% endif %}
<dt>Awarded by:</dt>
<dd><a href="{{ award.creator.get_absolute_url }}"
class="username">{{ award.creator }}</a></dd>
{% endif %}
{% if award.nomination %}
<dt>Nominated by:</dt>
<dd class="nominated_by"><a href="{{ award.nomination.creator.get_absolute_url }}"
class="username">{{ award.nomination.creator }}</a></dd>
<dt>Nomination approved by:</dt>
{% if award.badge.nominations_autoapproved %}
<dd class="nomination_approved_by"><span class="autoapproved">(auto-approved)</span></dd>
{% elif award.nomination.approver %}
<dd class="nomination_approved_by"><a href="{{ award.nomination.approver.get_absolute_url }}"
class="username">{{ award.nomination.approver }}</a></dd>
{% endif %}
{% else %}
<dt>Awarded by:</dt>
<dd><a href="{{ award.creator.get_absolute_url }}"
class="username">{{ award.creator }}</a></dd>
{% endif %}
<dt>Issued on:</dt>
<dd>{{ award.created }}</dd>
</dl>
Expand Down

0 comments on commit 86f9e3c

Please sign in to comment.