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

Commit

Permalink
Added GET with team filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
aandis committed Jan 30, 2016
1 parent 1d08e87 commit a97c089
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions www/~/%username/subscriptions.json.spt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
""" Get or change authenticated user's subscriptions.
"""
from aspen import Response
from gratipay.exceptions import NoTeam

[--------------------------------------------------------]
[------------------------------------------------------------------------]

if user.ANON:
raise Response(403, _("Please sign in first."))
Expand All @@ -11,16 +12,30 @@ else:
participant = user.participant

if request.method == 'GET':
subscriptions, totals = participant.get_giving_for_profile()
out = []
for s in subscriptions:
out.append({ "team_slug": s.team_slug,
"team_name": s.team_name,
"amount": str(s.amount),
"due": str(s.due),
"ctime": s.ctime,
"mtime": s.mtime
})
slug = request.qs.get("team_slug", "")

if slug: # Get subscription info only for this team.
try:
subscription = participant.get_payment_instruction(slug)
except NoTeam:
raise Response(400, _("Invalid team name."))
out = {
"amount" : str(subscription['amount']),
"ctime" : subscription['ctime'],
"mtime" : subscription['mtime']
}
else: # Get subscription info for all teams.
subscriptions, totals = participant.get_giving_for_profile()

out = []
for s in subscriptions:
out.append({ "team_slug": s.team_slug,
"team_name": s.team_name,
"amount": str(s.amount),
"due": str(s.due),
"ctime": s.ctime,
"mtime": s.mtime
})

[---] application/json
out

0 comments on commit a97c089

Please sign in to comment.