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

Commit

Permalink
Replace Profile > Giving with > Subscriptions
Browse files Browse the repository at this point in the history
Removes Profile > {Members,Receiving} entirely.
  • Loading branch information
chadwhitacre committed May 21, 2015
1 parent 5ee4e78 commit 33d49f0
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 90 deletions.
47 changes: 21 additions & 26 deletions gratipay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class NoOneToGiveFinalGiftTo(Exception): pass
def distribute_balance_as_final_gift(self, cursor):
"""Distribute a balance as a final gift.
"""
raise NotImplementedError # XXX Bring me back!
if self.balance == 0:
return

Expand Down Expand Up @@ -1310,49 +1311,43 @@ def get_tip_distribution(self):
return tip_amounts, npatrons, contributed


def get_giving_for_profile(self):
"""Given a participant id and a date, return a list and a Decimal.
This function is used to populate a participant's page for their own
viewing pleasure.
def get_subscriptions_for_profile(self):
"""Return a list and a Decimal.
"""

TIPS = """\
SUBSCRIPTIONS = """\
SELECT * FROM (
SELECT DISTINCT ON (tippee)
amount
, tippee
, t.ctime
, t.mtime
, p.claimed_time
, p.username_lower
, p.number
FROM tips t
JOIN participants p ON p.username = t.tippee
WHERE tipper = %s
AND p.is_suspicious IS NOT true
AND p.claimed_time IS NOT NULL
ORDER BY tippee
, t.mtime DESC
SELECT DISTINCT ON (s.team)
s.team as team_slug
, s.amount
, s.ctime
, s.mtime
, t.name as team_name
FROM subscriptions s
JOIN teams t ON s.team = t.slug
WHERE subscriber = %s
AND t.is_approved is true
AND t.is_closed is not true
ORDER BY s.team
, s.mtime DESC
) AS foo
ORDER BY amount DESC
, username_lower
, team_slug
"""
tips = self.db.all(TIPS, (self.username,))
subscriptions = self.db.all(SUBSCRIPTIONS, (self.username,))


# Compute the total.
# ==================

total = sum([t.amount for t in tips])
total = sum([s.amount for s in subscriptions])
if not total:
# If tips is an empty list, total is int 0. We want a Decimal.
total = Decimal('0.00')

return tips, total
return subscriptions, total

def get_current_tips(self):
"""Get the tips this participant is currently sending to others.
Expand Down
29 changes: 0 additions & 29 deletions js/gratipay/giving.js

This file was deleted.

29 changes: 29 additions & 0 deletions js/gratipay/subscriptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Gratipay.subscriptions = {}

Gratipay.subscriptions.init = function() {
Gratipay.subscriptions.activateTab('active');
$('.subscriptions #tab-nav a').on('click', Gratipay.subscriptions.handleClick);
}

Gratipay.subscriptions.handleClick = function(e) {
e.preventDefault();
var $target = $(e.target);
Gratipay.subscriptions.activateTab($target.data('tab'));
}

Gratipay.subscriptions.activateTab = function(tab) {
$.each($('.subscriptions #tab-nav a'), function(i, obj) {
var $obj = $(obj);
if ($obj.data('tab') == tab) {
$obj.addClass('selected');
} else {
$obj.removeClass('selected');
}
})

$.each($('.subscriptions .tab'), function(i, obj) {
var $obj = $(obj);
if ($obj.data('tab') == tab) { $obj.show(); } else { $obj.hide(); }
})
}

2 changes: 1 addition & 1 deletion scss/gratipay.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
@import "pages/history";
@import "pages/team";
@import "pages/profile-edit";
@import "pages/giving";
@import "pages/subscriptions";
@import "pages/settings";
@import "pages/cc-ba";
@import "pages/on-confirm";
Expand Down
2 changes: 1 addition & 1 deletion scss/pages/giving.scss → scss/pages/subscriptions.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.giving {
.subscriptions {
.note {
font: italic 12px/14px $Ideal;
}
Expand Down
4 changes: 1 addition & 3 deletions templates/profile-subnav.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
{% set u = participant.username %}
{% set pages = [ ('/', _('Dashboard'), True, False)
, ('/~'+u+'/', _('Profile'), True, show_profile)
, ('/~'+u+'/members/', _('Members'), show_members, show_members)
, ('/~'+u+'/receiving/', _('Receiving'), True, show_receiving)
, ('/~'+u+'/giving/', _('Giving'), True, False)
, ('/~'+u+'/subscriptions/', _('Subscriptions'), True, False)
, ('/~'+u+'/history/', _('History'), True, False)
, ('/~'+u+'/widgets/', _('Widgets'), True, False)
, ('/~'+u+'/identity', _('Identity'), True, False)
Expand Down
21 changes: 8 additions & 13 deletions templates/giving-table.html → templates/subscriptions-table.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% macro giving_table(state, tips, total) %}
{% macro subscriptions_table(state, subscriptions, total) %}
<table class="table">
<thead>
<tr>
<th>{{ _("Recipient") }}</th>
<th>{{ _("Team") }}</th>
{% if state != 'cancelled' %}
<th class="figure">{{ _("Amount ($)") }}</th>
{% endif %}
Expand All @@ -21,21 +21,16 @@
</tr>
</tfoot>
<tbody>
{% for tip in tips %}
{% for subscription in subscriptions %}
<tr>
<td class="recipient">
{% if state == 'unclaimed' %}
<img class="platform-icon" src="{{ website.asset('platforms/%s.12.png' % tip.platform) }}" />
<a href="/{{ tip.tippee }}/">{{ tip.user_name }}</a>
{% else %}
<a href="/{{ tip.tippee }}/">{{ tip.tippee }}</a>
{% endif %}
<td class="team">
<a href="/{{ subscription.team_slug }}/">{{ subscription.team_name }}</a>
</td>
{% if state != 'cancelled' %}
<td class="figure">{{ tip.amount }}</td>
<td class="figure">{{ subscription.amount }}</td>
{% endif %}
<td class="figure">{{ to_age(tip.mtime) }}</td>
<td class="figure">{{ to_age(tip.ctime) }}</td>
<td class="figure">{{ to_age(subscription.mtime) }}</td>
<td class="figure">{{ to_age(subscription.ctime) }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,50 @@ from datetime import timedelta
[-----------------------------------------------------------------------------]

participant = get_participant(state, restrict=True)
tips, total = participant.get_giving_for_profile()
subscriptions, total = participant.get_subscriptions_for_profile()
title = participant.username
subhead = _("Giving")
subhead = _("Subscriptions")
recently = utcnow() - timedelta(days=30)
cancelled_tips = [x for x in tips if x.amount == 0 and x.mtime >= recently]
cancelled_subscriptions = [x for x in subscriptions if x.amount == 0 and x.mtime >= recently]

# don't filter until after cancelled are looked at
tips = [t for t in tips if t.amount > 0]
subscriptions = [s for s in subscriptions if s.amount > 0]


tabs = {
'active': {
'tips': tips,
'ntips': len(tips),
'subscriptions': subscriptions,
'nsubscriptions': len(subscriptions),
'name': _("Active"),
'note': None,
'total': total
},
'cancelled': {
'tips': cancelled_tips,
'ntips': len(cancelled_tips),
'subscriptions': cancelled_subscriptions,
'nsubscriptions': len(cancelled_subscriptions),
'name': _("Cancelled"),
'note': _("These are tips that you recently cancelled."),
'note': _("These are subscriptions that you recently cancelled."),
'total': 0
}
}

[-----------------------------------------------------------------------------]
{% from 'templates/giving-table.html' import giving_table with context %}
{% from 'templates/subscriptions-table.html' import subscriptions_table with context %}

{% extends "templates/profile.html" %}

{% block scripts %}
<script>$(document).ready(Gratipay.giving.init);</script>
<script>$(document).ready(Gratipay.subscriptions.init);</script>
{{ super() }}
{% endblock %}

{% block content %}

<div class="giving">
<div class="subscriptions">

<p>{{ _("You give {0} every week.", format_currency(participant.giving, "USD")) }}</p>
<p>{{ _("You pay {0} every week.", format_currency(participant.giving, "USD")) }}</p>

<h2>{{ _("Tips") }}</h2>
<h2>{{ _("Subscriptions") }}</h2>

<ul class="nav" id="tab-nav">
{% for tab in ['active', 'cancelled'] %}
Expand All @@ -58,17 +58,17 @@ tabs = {

{% for tab in tabs.keys() %}
<div class='tab' data-tab='{{ tab }}'>
{% if tabs[tab]['ntips'] %}
{% if tabs[tab]['nsubscriptions'] %}

{% if tabs[tab]['note'] %}
<p class="note">{{ tabs[tab]['note'] }}</p>
{% endif %}

{{ giving_table(tab, tabs[tab]['tips'], tabs[tab]['total']) }}
{{ subscriptions_table(tab, tabs[tab]['subscriptions'], tabs[tab]['total']) }}

{% else %}

<p>{{ _("No tips to show") }}</p>
<p>{{ _("No subscriptions to show") }}</p>

{% endif %}
</div>
Expand Down

0 comments on commit 33d49f0

Please sign in to comment.