"""
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__)
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')
'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)
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;
}
% 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()">
←<span class="dollarsign">→
</%def>
<%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)}
--- /dev/null
+<%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)}