Skip to content

Commit

Permalink
Handled anonymous donors on the fundraising index page
Browse files Browse the repository at this point in the history
If someone opted to appear in the list but didn't provide
a name, "Anonymous Hero" will be used instead.
  • Loading branch information
bmispelon committed Feb 3, 2015
1 parent c5666f2 commit 41663bd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions djangoproject/templates/fundraising/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ <h1>Django Heroes</h1>
</div>
<div class="hero-name">
{% if donor.url %}<a href="{{ donor.url }}" rel="nofollow">{% endif %}{% spaceless %}
{{ donor.name }}
{{ donor.name_with_fallback }}
{% endspaceless %}{% if donor.url %}</a>{% endif %}
{% if donor.is_amount_displayed %}
<br/><em>${{ donor.donated_amount|intcomma }}</em>
Expand All @@ -136,7 +136,7 @@ <h1>Django Heroes</h1>
{% for donor in other_donors %}
<div class="no-logo-hero">
{% if donor.url %}<a href="{{ donor.url }}" rel="nofollow">{% endif %}{% spaceless %}
<span>{{ donor.name }}</span>
<span>{{ donor.name_with_fallback }}</span>
{% endspaceless %}{% if donor.url %}</a>{% endif %}
{% if donor.is_amount_displayed %}
<br/><em>${{ donor.donated_amount|intcomma }}</em>
Expand Down
4 changes: 4 additions & 0 deletions fundraising/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class Meta:
def thumbnail(self):
return get_thumbnail(self.logo, '170x170', quality=100)

@property
def name_with_fallback(self):
return self.name if self.name else 'Anonymous Hero'


@receiver(post_save, sender=DjangoHero)
def create_thumbnail_on_save(sender, **kwargs):
Expand Down
18 changes: 18 additions & 0 deletions fundraising/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ def test_donors_count(self):
response = self.client.get(reverse('fundraising:index'))
self.assertEqual(response.context['total_donors'], 1)

def test_anonymous_donor(self):
hero = DjangoHero.objects.create(is_visible=True, approved=True)
Donation.objects.create(donor=hero, amount='5')
response = self.client.get(reverse('fundraising:index'))
self.assertContains(response, 'Anonymous Hero')

def test_anonymous_donor_with_logo(self):
hero = DjangoHero.objects.create(is_visible=True, approved=True, logo='yes') # We don't need an actual image
Donation.objects.create(donor=hero, amount='5')
response = self.client.get(reverse('fundraising:index'))
self.assertContains(response, 'Anonymous Hero')

def test_hide_campaign_input(self):
# Checking if rendered output contains campaign form field
# to not generate ugly URLs
Expand Down Expand Up @@ -257,6 +269,12 @@ def test_thumbnail(self):
def test_thumbnail_no_logo(self):
self.assertIsNone(self.h2.thumbnail)

def test_name_with_fallback(self):
hero = DjangoHero()
self.assertEqual(hero.name_with_fallback, 'Anonymous Hero')
hero.name = 'Batistek'
self.assertEqual(hero.name_with_fallback, 'Batistek')


class TestPaymentForm(TestCase):
@patch('stripe.Customer.create')
Expand Down

0 comments on commit 41663bd

Please sign in to comment.