diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2013-09-14 01:00:16 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2013-09-14 01:00:16 +0200 |
commit | 4561ac0e95da990caf42bebaac7d3ca48deb53ce (patch) | |
tree | 2a1a30e46724aa8243720c827797b1c076b2f935 | |
parent | f475f0095f2b4af1acab8cfe3d6c866a71b73bf1 (diff) | |
download | kosten-4561ac0e95da990caf42bebaac7d3ca48deb53ce.tar.gz kosten-4561ac0e95da990caf42bebaac7d3ca48deb53ce.tar.bz2 kosten-4561ac0e95da990caf42bebaac7d3ca48deb53ce.zip |
Pie stuff
Diffstat (limited to '')
-rw-r--r-- | app/views/__init__.py | 2 | ||||
-rw-r--r-- | app/views/expenses.py | 21 | ||||
-rw-r--r-- | templates/expenses/show.jinja | 5 |
3 files changed, 21 insertions, 7 deletions
diff --git a/app/views/__init__.py b/app/views/__init__.py index 6405d3e..c4c362b 100644 --- a/app/views/__init__.py +++ b/app/views/__init__.py @@ -6,6 +6,8 @@ from .. import app, db # check for mobile visitors mobile_checks = ["J2ME", "Opera Mini"] +app.add_template_global(zip) + @app.before_request def handle_mobile(): ua = request.environ.get("HTTP_USER_AGENT", "") diff --git a/app/views/expenses.py b/app/views/expenses.py index 57a777a..893c367 100644 --- a/app/views/expenses.py +++ b/app/views/expenses.py @@ -27,6 +27,19 @@ def calc_month_exp(year, month): return MonthExpense(datetime.date(year, month, 1), exps) +def pie_stuff(exp): + expenses = {} + for c in exp.catexps: + expenses[c.cat.name] = float(c.expense) + + for c in Category.query.order_by(Category.name).all(): + yield (c.name, expenses.get(c.name, 0.0)) + +def calc_month_and_pie(year, month): + exp = calc_month_exp(year,month) + pie = pie_stuff(exp) + return (exp, dict(pie)) + @mod.app_template_filter() def prev_date(exp): if exp.date.month == 1: @@ -58,13 +71,13 @@ mod.add_url_rule("/<path:p>", endpoint = "show_date_str", build_only = True) def show(): d = datetime.date.today() - first = calc_month_exp(d.year, d.month) + first, pfirst = calc_month_and_pie(d.year, d.month) if d.month == 1: - second = calc_month_exp(d.year - 1, 12) + second, psecond = calc_month_and_pie(d.year - 1, 12) else: - second = calc_month_exp(d.year, d.month - 1) + second, psecond = calc_month_and_pie(d.year, d.month - 1) - return { 'exps' : [first, second] } + return { 'exps' : [first, second], 'pies': [pfirst, psecond] } @mod.route("/edit/<int:id>", methods=("GET", "POST")) @templated() diff --git a/templates/expenses/show.jinja b/templates/expenses/show.jinja index 8052757..4b6e362 100644 --- a/templates/expenses/show.jinja +++ b/templates/expenses/show.jinja @@ -12,7 +12,7 @@ {% endblock %} {% block content %} - {% for e in exps %} + {% for e, p in zip(exps,pies) %} {% if exps | length > 1 %}<h2>{{e|date}}</h2>{% endif %} <div style="margin-bottom: 10px"> <div style="display:inline-block; width:270px; vertical-align: top"> @@ -30,8 +30,7 @@ <a href="{{ url_for(".edit", id = exp.id) }}">{{exp.day}}.{{exp.month}}. -- {{exp.description}}: {{exp.expense | eur}}</a> {% endcall %} </div> - <div style="display:inline-block; height:250px; margin-left:50px"> - <object type="image/svg+xml" height="100%" data="{{ url_for("svg.month", month = e.date.month, year = e.date.year) }}"></object> + <div style="display:inline-block; height:250px; margin-left:50px" data-pie='{{ p | tojson }}'> </div> </div> {% endfor %} |