diff --git a/www/~/%username/subscriptions.json.spt b/www/~/%username/subscriptions.json.spt index c55fd9c55b..53901ef3bb 100644 --- a/www/~/%username/subscriptions.json.spt +++ b/www/~/%username/subscriptions.json.spt @@ -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.")) @@ -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 \ No newline at end of file