From c0cc786ed11a60845d1cd2a97c702f7f1d723409 Mon Sep 17 00:00:00 2001 From: Scott Torborg Date: Tue, 3 Nov 2009 21:41:13 -1000 Subject: [PATCH] added more 'my share' scope to status dashboard --- bluechips/controllers/status.py | 51 +++++++++++++++++++-------- bluechips/public/css/main.css | 19 ++++++++-- bluechips/templates/status/index.mako | 29 ++++++--------- 3 files changed, 63 insertions(+), 36 deletions(-) diff --git a/bluechips/controllers/status.py b/bluechips/controllers/status.py index 2532dfa..04ad79b 100644 --- a/bluechips/controllers/status.py +++ b/bluechips/controllers/status.py @@ -23,22 +23,35 @@ class StatusController(BaseController): c.debts = debts() c.settle = settle(c.debts) - c.total = self._total() - - year = date.today() - timedelta(days=365) - this_year = date.today().replace(month=1, day=1) - 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 = \ - [self._total(model.Expenditure.date >= i) - for i in [year, this_year, this_month]] + periods = {} + periods['Total'] = (None, None) + periods['Past year'] = (date.today() - timedelta(days=365), None) + periods['Year to date'] = (date.today().replace(month=1, day=1), None) + periods['Month to date'] = (date.today().replace(day=1), None) + periods['Last month'] = ((date.today() - + timedelta(days=30)).replace(day=1), + periods['Month to date'][0]) + c.totals = {} + for period in periods.keys(): + c.totals[period] = {} + start, end = periods[period] + conds = [] + if start is not None: + conds.append(model.Expenditure.date >= start) + if end is not None: + conds.append(model.Expenditure.date < end) + if len(conds) > 1: + conds = sqlalchemy.and_(*conds) + elif len(conds) > 0: + conds = conds[0] + else: + conds = None + + for scope in ('all', 'mine'): + meth = getattr(self, '_total_%s' % scope) + c.totals[period][scope] = meth(conds) - c.last_month_total = self._total(sqlalchemy.and_( - model.Expenditure.date >= last_month, - model.Expenditure.date < this_month)) - c.expenditures = meta.Session.query(model.Expenditure).\ filter(sqlalchemy.or_( model.Expenditure.spender == request.environ['user'], @@ -56,9 +69,17 @@ class StatusController(BaseController): return render('/status/index.mako') - def _total(self, conditions=None): + def _total_all(self, conditions=None): q = meta.Session.query(sqlalchemy.func.SUM( model.Expenditure.amount)) if conditions is not None: q = q.filter(conditions) return q.scalar() + + def _total_mine(self, conditions=None): + q = meta.Session.query(sqlalchemy.func.SUM( + model.Split.share)).join(model.Split.expenditure).\ + filter(model.Split.user == request.environ['user']) + if conditions is not None: + q = q.filter(conditions) + return q.scalar() diff --git a/bluechips/public/css/main.css b/bluechips/public/css/main.css index 35d5c1a..084666c 100644 --- a/bluechips/public/css/main.css +++ b/bluechips/public/css/main.css @@ -31,6 +31,12 @@ a:visited { #nav td { padding: 5px 20px; } +table { + border-collapse: collapse; +} +th, td { + padding: 2px 5px; +} div.block { margin: 10px 0; padding: 0 10px; @@ -40,17 +46,14 @@ table.form th { text-align: right; } table.list { - border-collapse: collapse; width: 100%; margin: 10px 0; } table.list th { text-align: left; - padding: 2px 5px; border-bottom: 1px solid #bbb; } table.list td { - padding: 2px 5px; vertical-align: top; } table.list td.date { @@ -71,6 +74,16 @@ table.list td.share { #totals th { text-align: right; } +#totals th.scope { + text-align: left; + padding: 2px 15px; +} +#totals .scope { + border-bottom: 1px solid #bbb; +} +#totals td { + padding: 2px 15px; +} #balance { margin-bottom: 10px; } diff --git a/bluechips/templates/status/index.mako b/bluechips/templates/status/index.mako index 014e7cb..cd851ee 100644 --- a/bluechips/templates/status/index.mako +++ b/bluechips/templates/status/index.mako @@ -30,25 +30,18 @@ - - - - - - - - - - - - - - - - - - + + + + % for period in ('Total', 'Past year', 'Year to date', 'Month to date', 'Last month'): + + + % for scope in ('all', 'mine'): + + % endfor + + % endfor
Total${c.total}
Past year${c.year_total}
Year to date${c.this_year_total}
Month to date${c.this_month_total}
Last month${c.last_month_total}EveryoneMy Share
${period}${c.totals[period][scope]}
-- 2.45.2