]> asedeno.scripts.mit.edu Git - bluechips.git/commitdiff
added more 'my share' scope to status dashboard
authorScott Torborg <scott@crookedmedia.com>
Wed, 4 Nov 2009 07:41:13 +0000 (21:41 -1000)
committerScott Torborg <scott@crookedmedia.com>
Wed, 4 Nov 2009 07:42:02 +0000 (21:42 -1000)
bluechips/controllers/status.py
bluechips/public/css/main.css
bluechips/templates/status/index.mako

index 2532dfac2da2d7189dc5bc15acdd1b22100d2c3a..04ad79b6a5bce8476f51942fe8172f81ca1770d5 100644 (file)
@@ -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()
index 35d5c1a4ac3347f8cd2c01a509fa7796e3ac104f..084666c5b6acee1cd4438ab27828cca3af44f492 100644 (file)
@@ -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;
 }
index 014e7cb4dcf9254c333c8a4acb909e5fcc253dea..cd851eec6062197f8f8e682d70ef3bc90125f5f3 100644 (file)
 
   <table id="totals">
     <tr>
-      <th>Total</th>
-      <td>${c.total}</td>
-    </tr>
-    <tr>
-      <th>Past year</th>
-      <td>${c.year_total}</td>
-    </tr>
-    <tr>
-      <th>Year to date</th>
-      <td>${c.this_year_total}</td>
-    </tr>
-    <tr>
-      <th>Month to date</th>
-      <td>${c.this_month_total}</td>
-    </tr>
-    <tr>
-      <th>Last month</th>
-      <td>${c.last_month_total}</td>
+      <td class="scope"></td>
+      <th class="scope">Everyone</th>
+      <th class="scope">My Share</th>
     </tr>
+    % for period in ('Total', 'Past year', 'Year to date', 'Month to date', 'Last month'):
+      <tr>
+        <th>${period}</th>
+        % for scope in ('all', 'mine'):
+          <td>${c.totals[period][scope]}</td>
+        % endfor
+      </tr>
+    % endfor
   </table>
 </div>