Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Beef up implementation of closed filtering
Browse files Browse the repository at this point in the history
Better match what we've already got.
  • Loading branch information
chadwhitacre committed Jan 12, 2017
1 parent 6b191f0 commit f2afb0e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions gratipay/models/participant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,13 +1077,11 @@ def profile_url(self):
return '{base_url}/{username}/'.format(**locals())


def get_teams(self, only_approved=False, cursor=None):
def get_teams(self, only_approved=False, only_open=False, cursor=None):
"""Return a list of teams this user is an owner or member of.
"""
teams = (cursor or self.db).all("""
SELECT teams.*::teams FROM teams WHERE
owner=%s AND
NOT is_closed
SELECT teams.*::teams FROM teams WHERE owner=%s
UNION
Expand All @@ -1094,6 +1092,8 @@ def get_teams(self, only_approved=False, cursor=None):
)
if only_approved:
teams = [t for t in teams if t.is_approved]
if only_open:
teams = [t for t in teams if not t.is_closed]
return teams


Expand Down
8 changes: 4 additions & 4 deletions templates/team-listing.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{% set approved_teams = participant.get_teams(only_approved=True) %}
{% set approved_open_teams = participant.get_teams(only_approved=True, only_open=True) %}

{% if (user.ADMIN or user.participant == participant) and approved_teams %}
{% if (user.ADMIN or user.participant == participant) and approved_open_teams %}
<h2>{{ _("Projects") }}</h2>
<ul class="team memberships">
{% for team in participant.get_teams() %}
<li><a href="/{{ team.slug }}/">{{ team.name }}</a></li>
{% endfor %}
</ul>
{% elif approved_teams %}
{% elif approved_open_teams %}
<h2>{{ _("Projects") }}</h2>
<ul class="team memberships">
{% for team in approved_teams %}
{% for team in approved_open_teams %}
<li><a href="/{{ team.slug }}/">{{ team.name }}</a></li>
{% endfor %}
</ul>
Expand Down
10 changes: 9 additions & 1 deletion tests/py/test_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,19 @@ def test_get_teams_can_get_only_approved_teams(self):
self.make_team('The Stargazer', owner=picard, is_approved=False)
assert [t.slug for t in picard.get_teams(only_approved=True)] == ['TheEnterprise']

def test_get_teams_can_get_only_open_teams(self):
self.make_team()
picard = P('picard')
self.make_team('The Stargazer', owner=picard, is_closed=False)
assert [t.slug for t in picard.get_teams(only_closed=True)] == ['TheEnterprise']

def test_get_teams_can_get_all_teams(self):
self.make_team(is_approved=True)
picard = P('picard')
self.make_team('The Stargazer', owner=picard, is_approved=False)
assert [t.slug for t in picard.get_teams()] == ['TheEnterprise', 'TheStargazer']
self.make_team('The Trident', owner=picard, is_approved=False, is_closed=True)
assert [t.slug for t in picard.get_teams()] == \
['TheEnterprise', 'TheStargazer', 'TheTrident']


# giving
Expand Down

0 comments on commit f2afb0e

Please sign in to comment.