From fed6d11d2cbd6d617d18bc01a78196865da4155b Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sun, 21 Mar 2010 01:36:17 -0400 Subject: [PATCH] Added UI for working with tags History page has a list of tags, with each tag linking to a page showing all expenses with that tag. --- bluechips/controllers/history.py | 16 +++++++++++++++- bluechips/model/__init__.py | 3 ++- bluechips/public/css/main.css | 6 ++++++ bluechips/templates/base.mako | 19 ++++++++++++++++++- bluechips/templates/history/index.mako | 5 +++-- bluechips/templates/history/tag.mako | 7 +++++++ 6 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 bluechips/templates/history/tag.mako diff --git a/bluechips/controllers/history.py b/bluechips/controllers/history.py index 833e34d..c3374dc 100644 --- a/bluechips/controllers/history.py +++ b/bluechips/controllers/history.py @@ -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') diff --git a/bluechips/model/__init__.py b/bluechips/model/__init__.py index fa8d7a8..ee991b7 100644 --- a/bluechips/model/__init__.py +++ b/bluechips/model/__init__.py @@ -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) diff --git a/bluechips/public/css/main.css b/bluechips/public/css/main.css index acaa339..62e0c7b 100644 --- a/bluechips/public/css/main.css +++ b/bluechips/public/css/main.css @@ -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; } diff --git a/bluechips/templates/base.mako b/bluechips/templates/base.mako index 888255c..43db6e4 100644 --- a/bluechips/templates/base.mako +++ b/bluechips/templates/base.mako @@ -84,7 +84,7 @@ % endif -<%def name="listExpenditures(es)"> +<%def name="listExpenditures(es, total=None, share=None)"> @@ -110,6 +110,15 @@ % endfor + % if total is not None and share is not None: + + + + + + + + % endif
Date
${total}${share}
@@ -142,6 +151,14 @@ +<%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 name="expenditureIcon()"> ← diff --git a/bluechips/templates/history/index.mako b/bluechips/templates/history/index.mako index 7921e0f..08d0aa7 100644 --- a/bluechips/templates/history/index.mako +++ b/bluechips/templates/history/index.mako @@ -1,9 +1,10 @@ <%inherit file="/base.mako"/> -

Group Expenditures

+

Tags

+${self.listTags()} +

Group Expenditures

${self.listExpenditures(c.expenditures)}

Transfers

- ${self.listTransfers(c.transfers)} diff --git a/bluechips/templates/history/tag.mako b/bluechips/templates/history/tag.mako new file mode 100644 index 0000000..2a5780d --- /dev/null +++ b/bluechips/templates/history/tag.mako @@ -0,0 +1,7 @@ +<%inherit file="/base.mako"/> + +

Tags

+${self.listTags()} + +

Expenditures tagged with ${c.tag.name}

+${self.listExpenditures(c.expenditures, total=c.total, share=c.share)} -- 2.45.2