]> asedeno.scripts.mit.edu Git - bluechips.git/commitdiff
Added UI for working with tags
authorRay Speth <speth@mit.edu>
Sun, 21 Mar 2010 05:36:17 +0000 (01:36 -0400)
committerAlejandro R. Sedeño <asedeno@mit.edu>
Wed, 23 Feb 2011 02:39:20 +0000 (21:39 -0500)
History page has a list of tags, with each tag linking to a page
showing all expenses with that tag.

bluechips/controllers/history.py
bluechips/model/__init__.py
bluechips/public/css/main.css
bluechips/templates/base.mako
bluechips/templates/history/index.mako
bluechips/templates/history/tag.mako [new file with mode: 0644]

index 833e34d4529ec9db63064a463dfaa41643906c75..c3374dc77e3ea0af969519a525113d3a6ba17c75 100644 (file)
@@ -3,11 +3,12 @@ Display old transactions
 """
 
 import logging
+from pylons import request
 
 from bluechips.lib.base import *
 from bluechips.lib.totals import *
 
-import sqlalchemy
+import sqlalchemy as sa
 from sqlalchemy import orm
 
 log = logging.getLogger(__name__)
@@ -16,8 +17,21 @@ class HistoryController(BaseController):
     def index(self):
         c.title = 'History'
         
+        c.tags = meta.Session.query(model.Tag).order_by([sa.func.lower(model.Tag.name)])
         c.expenditures = meta.Session.query(model.Expenditure).\
                 options(orm.eagerload('splits')).all()
         c.transfers = meta.Session.query(model.Transfer).all()
 
         return render('/history/index.mako')
+
+
+    def tag(self, id=None):
+        c.title = 'History'
+
+        c.tags = meta.Session.query(model.Tag).order_by([sa.func.lower(model.Tag.name)])
+        c.tag = meta.Session.query(model.Tag).filter_by(id=id).all()[0]
+        c.expenditures = c.tag.expenditures
+        c.total = sum([e.amount for e in c.expenditures])
+        c.share = sum([e.share(request.environ['user']) for e in c.expenditures])
+
+        return render('/history/tag.mako')
index fa8d7a88239b5b94e5fa202461847a7a29b2c440..ee991b75abbc127abf67ed194f24ff89a301f1a8 100644 (file)
@@ -111,7 +111,8 @@ orm.mapper(Split, splits, properties={
         'user': orm.relation(User)
 })
 
-orm.mapper(Tag, tags)
+orm.mapper(Tag, tags, properties={
+        'expenditures': orm.relation(Expenditure, secondary=tag_to_expense_map)})
 
 orm.mapper(Subitem, subitems, properties={
         'user': orm.relation(User)
index acaa339ddf47f5349a9056e9545cb6a9ede40256..62e0c7bc5a8418373037ee41b5084e0ea7c62102 100644 (file)
@@ -85,6 +85,12 @@ table.list td.share {
 table.list td.editlink {
     width: 30px;
 }
+table.list td.total {
+   border-top: 1px solid #bbb;
+   text-align: right;
+   font-weight: bold;
+}
+
 #totals {
     margin-bottom: 10px;
 }
index 888255cbb085affec730b973cd462278eb439625..43db6e4246c1871b543fc69aa83ca5a6c66c3618 100644 (file)
@@ -84,7 +84,7 @@
   % endif
 </%def>
 
-<%def name="listExpenditures(es)">
+<%def name="listExpenditures(es, total=None, share=None)">
   <table class="list">
     <tr>
       <th class="date">Date</th>
         <td class="editlink">${h.link_to('Edit', h.url_for(controller='spend', action='edit', id=e.id))}</td>
       </tr>
     % endfor
+    % if total is not None and share is not None:
+      <tr class="user-involved">
+        <td class="total" colspan=3></td>
+       <td class="total">${total}</td>
+       <td class="total">${share}</td>
+       <td class="total"></td>
+      </tr>
+
+    % endif
   </table>
 </%def>
 
   </table>
 </%def>
 
+<%def name="listTags()">
+<%
+x = ',\n'.join([h.link_to(tag.name, h.url_for(controller='history', action='tag', id=tag.id)) for tag in c.tags])
+%>
+${x|n}
+</%def>
+
+
 <%def name="expenditureIcon()">
 &larr;<span class="dollarsign">&rarr;
 </%def>
index 7921e0f62dc9c66ef1fca1e2b6f64edda277e330..08d0aa736db3516d9d32c164f9c9480a7f47363b 100644 (file)
@@ -1,9 +1,10 @@
 <%inherit file="/base.mako"/>
 
-<h2>Group Expenditures</h2>
+<h2>Tags</h2>
+${self.listTags()}
 
+<h2>Group Expenditures</h2>
 ${self.listExpenditures(c.expenditures)}
 
 <h2>Transfers</h2>
-
 ${self.listTransfers(c.transfers)}
diff --git a/bluechips/templates/history/tag.mako b/bluechips/templates/history/tag.mako
new file mode 100644 (file)
index 0000000..2a5780d
--- /dev/null
@@ -0,0 +1,7 @@
+<%inherit file="/base.mako"/>
+
+<h2>Tags</h2>
+${self.listTags()}
+
+<h2>Expenditures tagged with ${c.tag.name}</h2>
+${self.listExpenditures(c.expenditures, total=c.total, share=c.share)}