from paste.urlparser import StaticURLParser
from paste.deploy.converters import asbool
from pylons import config
-from pylons.middleware import ErrorHandler, StaticJavascripts, \
- StatusCodeRedirect
+from pylons.middleware import ErrorHandler, StatusCodeRedirect
from pylons.wsgiapp import PylonsApp
from routes.middleware import RoutesMiddleware
from paste import httpexceptions
this_month = date.today().replace(day=1)
last_month = (date.today() - timedelta(days=30)).replace(day=1)
- c.year_total, c.this_year_total, c.this_month_total =\
+ c.year_total, c.this_year_total, c.this_month_total = \
[self._total(model.expenditures.c.date >= i)
for i in [year, this_year, this_month]]
but return the "subclass's" type
"""
-def wrapper(c, func):
- return (lambda self,*args: c(getattr(self.value, func)(*map(self.value.__class__, args))))
+def wrapper(cls, func):
+ return (lambda self, *args: cls(getattr(self.value, func)(*map(self.value.__class__, args))))
class SmartSubclass(object):
- def __init__(self, superclass, exclude=[]):
+ def __init__(self, superclass, exclude=None):
+ if exclude is None:
+ exclude = []
self.superclass = superclass
self.exclude = exclude
def __call__(self, name, bases, dict):
# house
users = meta.Session.query(model.User)
- debts = {}
+ debts_dict = {}
# First, credit everyone for expenditures they've made
for user in users:
- debts[user] = Currency(-sum(map((lambda x: x.amount), user.expenditures)))
+ debts_dict[user] = Currency(-sum(map((lambda x: x.amount), user.expenditures)))
# Next, debit everyone for expenditures that they have an
# investment in (i.e. splits)
group_by(model.Split.user_id)
for split, total_cents in total_splits:
- debts[split.user] += total_cents
+ debts_dict[split.user] += total_cents
# Finally, move transfers around appropriately
#
total_credits = transfer_q.group_by(model.Transfer.creditor_id)
for transfer, total_amount in total_debits:
- debts[transfer.debtor] -= total_amount
+ debts_dict[transfer.debtor] -= total_amount
for transfer, total_amount in total_credits:
- debts[transfer.creditor] += total_amount
+ debts_dict[transfer.creditor] += total_amount
- return debts
+ return debts_dict
def settle(debts_dict):
# This algorithm has been shamelessly stolen from Nelson Elhage's
owes_list = [debt for debt in debts_list if debt['amount'] > 0]
owed_list = [debt for debt in debts_list if debt['amount'] < 0]
- settle = []
+ settle_list = []
while len(owes_list) > 0 and len(owed_list) > 0:
owes = owes_list[0]
owes_list.pop(0)
val = owes['amount']
- settle.append((owes['who'], owed['who'], val))
+ settle_list.append((owes['who'], owed['who'], val))
if len(owes_list) > 0:
raise DirtyBooks, ("People still owe money", owes_list)
if len(owed_list) > 0:
raise DirtyBooks, ("People are still owed money", owed_list)
- return settle
+ return settle_list
__all__ = ['debts', 'settle']
import sqlalchemy as sa
from sqlalchemy import orm
-from user import *
-from expenditure import *
-from split import *
-from subitem import *
-from transfer import *
+from bluechips.model.user import User
+from bluechips.model.expenditure import Expenditure
+from bluechips.model.split import Split
+from bluechips.model.subitem import Subitem
+from bluechips.model.transfer import Transfer
from bluechips.model import meta
from bluechips.model import types
-from user import User
-from split import Split
+from bluechips.model.user import User
+from bluechips.model.split import Split
from bluechips.model import meta
from bluechips.model.types import Currency
from decimal import Decimal