Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aggregator/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def setUp(self, mocker):
def test_community_index_number_of_queries(self):
"""Intended to prevent an n+1 issue on the community index view"""
url = reverse("community-index")
with self.assertNumQueries(7):
with self.assertNumQueries(8):
self.client.get(url)

def test_empty_feed_type_not_rendered(self):
Expand Down
6 changes: 5 additions & 1 deletion djangoproject/templates/aggregator/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base_community.html" %}
{% load i18n %}
{% load fundraising_extras i18n %}

{% block layout_class %}column-container sidebar-right{% endblock %}

Expand Down Expand Up @@ -97,3 +97,7 @@ <h2 class="bullet-icon"><i class="icon icon-rss blue"></i> {{ feedtype.name }}</
{% endfor %}
</ul>
{% endblock %}

{% block content-related-extra %}
{% top_and_gold_corporate_members %}
{% endblock %}
3 changes: 3 additions & 0 deletions djangoproject/templates/base_community.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
{% block content-related %}
<div role="complementary">
<h2 class="visuallyhidden" id="aside-header">{% translate "Additional Information" %}</h2>

{% block content-related-extra %}{% endblock %}

{% donation_snippet %}

<h3>{% translate "More Help" %}</h3>
Expand Down
3 changes: 3 additions & 0 deletions djangoproject/templates/base_foundation.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
{# Always include <h2> label and <div> with aria role. #}
<div role="complementary">
<h2 class="visuallyhidden" id="aside-header">{% translate "Additional Information" %}</h2>

{% block content-related-extra %}{% endblock %}

{% donation_snippet %}

<h3>About the foundation</h3>
Expand Down
6 changes: 5 additions & 1 deletion djangoproject/templates/flatpages/foundation.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base_foundation.html" %}

{% load fundraising_extras %}
{% block og_title %}{{ flatpage.title }}{% endblock %}

{% block title %}{{ flatpage.title }}{% endblock %}
Expand All @@ -8,3 +8,7 @@
<h1>{{ flatpage.title }}</h1>
{{ flatpage.content }}
{% endblock %}

{% block content-related-extra %}
{% top_and_gold_corporate_members %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% if members %}
<div class="corporate-members">
<h3>Diamond, Platinum and Gold Members</h3>
{% for obj in members %}
<div class="clearfix">
<div class="member-logo">
<a href="{{ obj.url }}" title="{{ obj.display_name }}">
<img src="{{ obj.thumbnail.url }}" alt="{{ obj.display_name }}" />
</a>
</div>
<div class="small-cta">
<ul class="list-links-small">
<li><strong>{{ obj.display_name }}</strong></li>
<li><a href="{{ obj.url }}" title="{{ obj.display_name }}">
{{ obj.description }}
</a></li>
</ul>
</div>
</div>
{% endfor %}
</div>
{% endif %}
7 changes: 7 additions & 0 deletions fundraising/templatetags/fundraising_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,10 @@ def top_corporate_members():
members = CorporateMember.objects.by_membership_level()

return {"members": members["diamond"] + members["platinum"]}


@register.inclusion_tag("fundraising/includes/top_and_gold_corporate_members.html")
def top_and_gold_corporate_members():
members = CorporateMember.objects.by_membership_level()

return {"members": members["diamond"] + members["platinum"] + members["gold"]}
Comment on lines +121 to +127
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a new template and new tag I think we could make the existing tag more generic like

@register.inclusion_tag("fundraising/includes/top_corporate_members.html")
def top_corporate_members(*levels, header=None):
    """
    Usage: {% top_corporate_members "diamond" "platinum" header="Diamond and Platinum Members" %}
    """

    all_members = CorporateMember.objects.by_membership_level()

    members = []
    for level in levels:
        if level in all_members:
            members += all_members[level]

    return {"header": header, "members": members}

and render the header in the template like <h3>{{ header }}</h3>

53 changes: 53 additions & 0 deletions fundraising/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..templatetags.fundraising_extras import (
display_django_heroes,
donation_form_with_heart,
top_and_gold_corporate_members,
top_corporate_members,
)

Expand Down Expand Up @@ -167,3 +168,55 @@ def test_with_diamond_members_and_platinum_members(self):
expected = [member_5, member_4, member_6, member_2, member_1, member_3]

self.assertEqual(members, expected)


class TestTopAndGoldCorporateMembers(TestCase):
past_date = date(2000, 1, 1)
future_date = date(3000, 1, 1)

def test_with_no_gold_members(self):
members = top_and_gold_corporate_members()["members"]
self.assertEqual(members, [])

def test_with_gold_members(self):
member_1 = CorporateMember.objects.create(membership_level=3)
member_2 = CorporateMember.objects.create(membership_level=3)
member_3 = CorporateMember.objects.create(membership_level=3)

member_1.invoice_set.create(amount=4, expiration_date=self.future_date)
member_2.invoice_set.create(amount=8, expiration_date=self.future_date)
member_3.invoice_set.create(amount=2, expiration_date=self.future_date)

members = top_and_gold_corporate_members()["members"]

self.assertEqual(members, [member_2, member_1, member_3])

def test_with_gold_members_and_other_members(self):
member_1 = CorporateMember.objects.create(membership_level=3)
member_2 = CorporateMember.objects.create(membership_level=3)
member_3 = CorporateMember.objects.create(membership_level=4)
member_4 = CorporateMember.objects.create(membership_level=5)
member_5 = CorporateMember.objects.create(membership_level=2)

member_1.invoice_set.create(amount=4, expiration_date=self.future_date)
member_2.invoice_set.create(amount=8, expiration_date=self.future_date)
member_3.invoice_set.create(amount=2, expiration_date=self.future_date)
member_4.invoice_set.create(amount=2, expiration_date=self.future_date)
member_5.invoice_set.create(amount=2, expiration_date=self.future_date)

members = top_and_gold_corporate_members()["members"]
self.assertEqual(members, [member_4, member_3, member_2, member_1])
self.assertNotIn(member_5, members)

def test_with_gold_members_and_expired_invoice(self):
member_1 = CorporateMember.objects.create(membership_level=3)
member_2 = CorporateMember.objects.create(membership_level=3)
member_3 = CorporateMember.objects.create(membership_level=4)

member_1.invoice_set.create(amount=4, expiration_date=self.future_date)
member_2.invoice_set.create(amount=8, expiration_date=self.future_date)
member_3.invoice_set.create(amount=2, expiration_date=self.past_date)

members = top_and_gold_corporate_members()["members"]
self.assertEqual(members, [member_2, member_1])
self.assertNotIn(member_3, members)