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

Commit

Permalink
Implement funding goal feature (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Jul 12, 2012
1 parent a6ad00c commit ce0db99
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 129 deletions.
60 changes: 28 additions & 32 deletions gittip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import datetime
import locale
from decimal import Decimal


locale.setlocale(locale.LC_ALL, "en_US")


BIRTHDAY = datetime.date(2012, 6, 1)
CARDINALS = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
def age():
Expand Down Expand Up @@ -79,45 +84,36 @@ def get_backed_amount(participant_id):
return amount


def get_tipjar(participant_id, pronoun="their", claimed=False):
"""Given a participant id, return a unicode.
def get_number_of_backers(participant_id):
"""Given a unicode, return an int.
"""

amount = get_backed_amount(participant_id)


# Compute a unicode describing the amount.
# ========================================
# This is down here because we use it in multiple places in the app,
# basically in the claimed participant page and the non-claimed GitHub page
# (hopefully soon to be Facebook and Twitter as well).
BACKED = """\
if pronoun not in ('your', 'their'):
raise Exception("Unknown, um, pronoun: %s" % pronoun)
SELECT count(amount) AS nbackers
FROM ( SELECT DISTINCT ON (tipper)
amount
, tipper
FROM tips
JOIN participants p ON p.id = tipper
WHERE tippee=%s
AND last_bill_result = ''
ORDER BY tipper
, mtime DESC
) AS foo
WHERE amount > 0
if amount == 0:
if pronoun == "your":
tipjar = u"have no backed tips."
elif pronoun == "their":
tipjar = u"has no backed tips."
"""
rec = db.fetchone(BACKED, (participant_id,))
if rec is None:
nbackers = None
else:
if pronoun == "your":
tipjar = u"have $%s in backed tips."
elif pronoun == "their":
tipjar = u"has $%s in backed tips."
tipjar %= amount


# We're opt-in.
# =============
# If the user hasn't claimed the tipjar then the tips are only pledges,
# we're not going to actually collect money on their behalf.

if not claimed:
tipjar = tipjar.replace("backed", "pledged")
nbackers = rec['nbackers'] # might be None

if nbackers is None:
nbackers = 0

return tipjar
return nbackers


def get_tips_and_total(tipper, for_payday=False):
Expand Down
1 change: 1 addition & 0 deletions gittip/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def load_session(where, val):
, p.is_admin
, p.redirect
, p.balance
, p.goal
, n.network
, n.user_info
FROM participants p
Expand Down
17 changes: 0 additions & 17 deletions gittip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@ def wrap(u):
return u if u else '...'


def commaize(n, places=1):
"""Given a number, return a string with commas and a decimal -- 1,000.0.
"""
out = ("%%.0%df" % places) % n
try:
whole, fraction = out.split('.')
except ValueError:
whole, fraction = (out, '')
_whole = []
for i, digit in enumerate(reversed(whole), start=1):
_whole.insert(0, digit)
if i % 3 == 0:
_whole.insert(0, ',')
out = ''.join(_whole + ['.', fraction]).lstrip(',').rstrip('.')
return out


def total_seconds(td):
"""
Python 2.7 adds a total_seconds method to timedelta objects.
Expand Down
23 changes: 14 additions & 9 deletions schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
-- million trillion trillion
-- | trillion trillion
-- | | trillion
-- | | | billion
-- | | | | million
-- | | | | | thousand
-- | | | | | |
-- numeric(35,2) maxes out at $999,999,999,999,999,999,999,999,999,999,999.00.


-- Create the initial structure.

CREATE EXTENSION hstore;
Expand Down Expand Up @@ -82,16 +92,11 @@ CREATE TABLE exchanges
, participant_id text NOT NULL REFERENCES participants ON DELETE RESTRICT
);

-- million trillion trillion
-- | trillion trillion
-- | | trillion
-- | | | billion
-- | | | | million
-- | | | | | thousand
-- | | | | | |
-- numeric(34,2) maxes out at $999,999,999,999,999,999,999,999,999,999,999.00.


-- https://github.com/whit537/www.gittip.com/issues/128
ALTER TABLE participants ADD COLUMN anonymous bool NOT NULL DEFAULT FALSE;
ALTER TABLE participants DROP COLUMN shares_giving;


-- https://github.com/whit537/www.gittip.com/issues/110
ALTER TABLE participants ADD COLUMN goal numeric(35,2) DEFAULT NULL;
Loading

0 comments on commit ce0db99

Please sign in to comment.