From bcc2e4fcec619078059102dbd5c8172010390a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Mon, 15 Apr 2013 00:59:59 +0200 Subject: Some reorganizing --- app/views/categories.py | 7 +++-- app/views/consts.py | 16 +++++----- app/views/expenses.py | 9 ++++-- templates/categories/manage.jinja | 22 ++++++++++++++ templates/consts/add.jinja | 13 ++++++++ templates/consts/edit.jinja | 14 +++++++++ templates/consts/list.jinja | 23 +++++++++++++++ templates/consts/show.jinja | 39 ++++++++++++++++++++++++ templates/expenses/add.jinja | 24 +++++++++++++++ templates/expenses/edit.jinja | 14 +++++++++ templates/expenses/show.jinja | 62 +++++++++++++++++++++++++++++++++++++++ templates/layout.jinja | 57 +++++++++++++++++++++++++++++++++++ templates/macros.jinja | 35 ++++++++++++++++++++++ templates/menu.jinja | 4 +-- templates/page.jinja | 37 ----------------------- templates/pages/add.jinja | 25 ---------------- templates/pages/cats.jinja | 22 -------------- templates/pages/const.jinja | 39 ------------------------ templates/pages/constadd.jinja | 12 -------- templates/pages/constedit.jinja | 13 -------- templates/pages/constlist.jinja | 23 --------------- templates/pages/edit.jinja | 10 ------- templates/pages/show.jinja | 62 --------------------------------------- templates/root.jinja | 57 ----------------------------------- 24 files changed, 325 insertions(+), 314 deletions(-) create mode 100644 templates/categories/manage.jinja create mode 100644 templates/consts/add.jinja create mode 100644 templates/consts/edit.jinja create mode 100644 templates/consts/list.jinja create mode 100644 templates/consts/show.jinja create mode 100644 templates/expenses/add.jinja create mode 100644 templates/expenses/edit.jinja create mode 100644 templates/expenses/show.jinja create mode 100644 templates/layout.jinja create mode 100644 templates/macros.jinja delete mode 100644 templates/page.jinja delete mode 100644 templates/pages/add.jinja delete mode 100644 templates/pages/cats.jinja delete mode 100644 templates/pages/const.jinja delete mode 100644 templates/pages/constadd.jinja delete mode 100644 templates/pages/constedit.jinja delete mode 100644 templates/pages/constlist.jinja delete mode 100644 templates/pages/edit.jinja delete mode 100644 templates/pages/show.jinja delete mode 100644 templates/root.jinja diff --git a/app/views/categories.py b/app/views/categories.py index 902959b..e020a11 100644 --- a/app/views/categories.py +++ b/app/views/categories.py @@ -5,8 +5,11 @@ from ..model import Category mod = Blueprint('categories', __name__) +def T(tpl): + return "categories/%s.jinja" % tpl + @mod.route("/") -def all (): +def manage (): categories = Category.query.order_by(Category.name).all() - return render_template("pages/cats.jinja", cats = categories) + return render_template(T("manage"), cats = categories) diff --git a/app/views/consts.py b/app/views/consts.py index f1e4ebd..a4980fb 100644 --- a/app/views/consts.py +++ b/app/views/consts.py @@ -9,6 +9,9 @@ from ..forms import ConstForm, today mod = Blueprint('consts', __name__) +def T(tpl): + return "consts/%s.jinja" % tpl + def const_form(cur=None, obj=None): obj = cur if obj is None else obj form = ConstForm(obj=obj) @@ -27,9 +30,8 @@ def const_form(cur=None, obj=None): return form - @mod.route("/") -def all (): +def list (): d = today() expenses = ConstExpense.query.order_by(ConstExpense.start).all() @@ -47,11 +49,11 @@ def all (): else: future.append(e) - return render_template("pages/constlist.jinja", current = current, old = old, future = future) + return render_template(T("list"), current = current, old = old, future = future) @mod.route("/") def show(id): - return render_template("pages/const.jinja", exp = ConstExpense.get(id)) + return render_template(T("show"), exp = ConstExpense.get(id)) @mod.route("/edit/", methods=("GET", "POST")) def edit(id): @@ -62,14 +64,14 @@ def edit(id): if "deleteB" in request.form: db.session.delete(exp) db.session.commit() - return redirect(url_for(".all")) + return redirect(url_for(".list")) elif form.validate(): # change form.populate_obj(exp) db.session.commit() return redirect(url_for(".show", id = exp.id)) - return render_template("pages/constedit.jinja", form=form) + return render_template(T("edit"), form=form) @mod.route("/add/from/") def add_from(other): @@ -100,4 +102,4 @@ def add (form=None): db.session.commit() return redirect(url_for(".show", id = exp.id)) - return render_template("pages/constadd.jinja", form = form) + return render_template(T("add"), form = form) diff --git a/app/views/expenses.py b/app/views/expenses.py index 512c906..56b7452 100644 --- a/app/views/expenses.py +++ b/app/views/expenses.py @@ -10,6 +10,9 @@ from ..forms import ExpenseForm mod = Blueprint('expenses', __name__) +def T(tpl): + return "expenses/%s.jinja" % tpl + def expense_form(obj=None): form = ExpenseForm(obj=obj) form.category.query = Category.query.order_by(Category.name) @@ -61,14 +64,14 @@ def show(): else: second = calc_month_exp(d.year, d.month - 1) - return render_template("pages/show.jinja", exps = [first, second]) + return render_template(T("show"), exps = [first, second]) @mod.route("/edit/", methods=("GET", "POST")) def edit(id): exp = SingleExpense.get(id) form = expense_form(exp) - ret = lambda: render_template("pages/edit.jinja", form=form) + ret = lambda: render_template(T("edit"), form=form) if request.method == "POST": if "deleteB" in request.form: @@ -99,4 +102,4 @@ def add(): return redirect(url_for("index")) - return render_template("pages/add.jinja", form=form) + return render_template(T("add"), form=form) diff --git a/templates/categories/manage.jinja b/templates/categories/manage.jinja new file mode 100644 index 0000000..efa91b6 --- /dev/null +++ b/templates/categories/manage.jinja @@ -0,0 +1,22 @@ +{% extends "layout.jinja" %} + +{% block heading %} Kategorien {% endblock %} + +{% block js %} + {{ super() }} + +{% endblock %} + +{% block content %} +
+
    + {% for c in cats %} +
  • {{c.name}}
  • + {%- endfor %} +
    +
+ +
+ +{% endblock %} + diff --git a/templates/consts/add.jinja b/templates/consts/add.jinja new file mode 100644 index 0000000..1ddad4a --- /dev/null +++ b/templates/consts/add.jinja @@ -0,0 +1,13 @@ +{% extends "layout.jinja" %} +{% from "macros.jinja" import render_form %} + +{% block heading %} + Füge neue konstante Ausgabe hinzu +{% endblock %} + +{% block content %} +
+ {{ render_form(form) }} + +
+{% endblock %} diff --git a/templates/consts/edit.jinja b/templates/consts/edit.jinja new file mode 100644 index 0000000..b313704 --- /dev/null +++ b/templates/consts/edit.jinja @@ -0,0 +1,14 @@ +{% extends "layout.jinja" %} +{% from "macros.jinja" import render_form %} + +{% block heading %} + Konstante Ausgabe bearbeiten +{% endblock %} + +{% block content %} +
+ {{ render_form(form) }} + + +
+{% endblock %} diff --git a/templates/consts/list.jinja b/templates/consts/list.jinja new file mode 100644 index 0000000..68fa1e1 --- /dev/null +++ b/templates/consts/list.jinja @@ -0,0 +1,23 @@ +{% extends "layout.jinja" %} + +{% block heading %} + Konstante Kosten +{% endblock %} + +{% block content %} +

Neuen Eintrag hinzufügen

+ + {{ list(current, "Aktuell") }} + + {% if future %} {{ list(future, "Zukünftige") }} {% endif %} + {% if old %} {{ list(old, "Veraltet") }} {% endif %} +{% endblock %} + +{% macro list(list, h) %} +

{{ h }}

+ +{% endmacro %} diff --git a/templates/consts/show.jinja b/templates/consts/show.jinja new file mode 100644 index 0000000..c09fc3b --- /dev/null +++ b/templates/consts/show.jinja @@ -0,0 +1,39 @@ +{% extends "layout.jinja" %} +{% from "macros.jinja" import left_arrow, right_arrow %} +{% set fmt="%m.%Y" %} + +{% block heading %} + Konstante Kosten +{% endblock %} + +{% block content %} +
    +
  • Beschreibung: {{exp.description}}
  • +
  • Kategorie: {{exp.category.name}}
  • +
  • Betrag: {{exp.expense | eur}}
  • +
  • Betrag pro Monat: {{exp.monthly | eur}}
  • +
  • Start: {{exp.start | date(format=fmt)}}
  • +
  • Ende: {{exp.end | date(format=fmt)}}
  • +
  • Zahlungsrhythmus: + {% if exp.months == 1 %} + monatlich + {% elif exp.months == 6 %} + halbjährlich + {% elif exp.months == 12 %} + jährlich + {% else %} + alle {{exp.months}} Monate + {% endif %} +
+

+ Bearbeiten  + Erstelle neuen auf dem jetzigen basierenden Eintrag +

+ {% if exp.prev %} {{ left_arrow(url_for(".show", id = exp.prev.id), target(exp.prev)) }} {% endif %} + {% if exp.next %} {{ right_arrow(url_for(".show", id = exp.next.id), target(exp.next)) }} {% endif %} +{% endblock %} + +{% macro target(p) -%} + {{ p.description }} ({{ p.start | date(fmt) ~ "-" ~ p.end | date(fmt) }})
+ {{ p.expense | eur }} +{%- endmacro %} diff --git a/templates/expenses/add.jinja b/templates/expenses/add.jinja new file mode 100644 index 0000000..de54de3 --- /dev/null +++ b/templates/expenses/add.jinja @@ -0,0 +1,24 @@ +{% extends "layout.jinja" %} +{% from "macros.jinja" import render_form %} + +{% block heading %} + Neue Ausgabe hinzufügen +{% endblock %} + +{% block js %} + {{ super() }} + + +{% endblock %} + +{% block style %} + {{ super() }} + +{% endblock %} + +{% block content %} +
+ {{ render_form(form) }} + +
+{% endblock %} diff --git a/templates/expenses/edit.jinja b/templates/expenses/edit.jinja new file mode 100644 index 0000000..c871eb1 --- /dev/null +++ b/templates/expenses/edit.jinja @@ -0,0 +1,14 @@ +{% extends "expenses/add.jinja" %} +{% from "macros.jinja" import render_form %} + +{% block heading %} + Bearbeite Kosteneintrag +{% endblock %} + +{% block content %} +
+ {{ render_form(form) }} + + +
+{% endblock %} diff --git a/templates/expenses/show.jinja b/templates/expenses/show.jinja new file mode 100644 index 0000000..2643ac4 --- /dev/null +++ b/templates/expenses/show.jinja @@ -0,0 +1,62 @@ +{% extends "layout.jinja" %} +{% from "macros.jinja" import left_arrow, right_arrow, colorize %} + +{% block heading %} + {% if exps | length > 1 %} + Aktuelle Kosten + {% else %} + Kosten für {{exps[0]|date}} + {% endif %} +{% endblock %} + +{% block js %} + {{ super() }} + +{% endblock %} + +{% block content %} + {% for e in exps %} + {% if exps | length > 1 %}

{{e|date}}

{% endif %} + {% for c in e.catexps | sort(attribute="cat.name") %} + {% call(exp) detail(name=c.cat.name, sum=c.expense, set=c.all) %} + {{exp.day}}.{{exp.month}}. -- {{exp.description}}: {{exp.expense | eur }} + {% endcall %} + {% endfor %} + + {% call(exp) detail(name="Constant", sum=e.constsum, set=e.consts) %} + {{exp.monthly}} -- {{exp.description}} + {% endcall %} + + {% call(exp) detail(name="In Summa", sum=e.sum, set=e.all, color="#ff2d2d") %} + {{exp.day}}.{{exp.month}}. -- {{exp.description}}: {{exp.expense | eur}} + {% endcall %} +
+ {% endfor %} + + {# Note: exps are given _reversed_, i.e. "exps | last" is + the _first_ on the timeline #} + {% set d = exps | last | prev_date | date %} + {{ left_arrow(url_for(".show_date_str", p = d), d) }} + + {% set first = exps | first %} + {% if not first is last_date %} + {% set d = first | next_date | date %} + {{ right_arrow(url_for(".show_date_str", p = d), d) }} + {% endif %} +{% endblock content %} + +{% macro detail(name, sum, set, color=None) %} +
+ + {% call colorize(fgcolor=color) %} + {{name}}: {{sum | eur}}
+ {% endcall %} +
+
    + {% for exp in set %} +
  • {{ caller(exp) }}
  • + {% endfor %} +
+
+
+{% endmacro %} diff --git a/templates/layout.jinja b/templates/layout.jinja new file mode 100644 index 0000000..dcddc33 --- /dev/null +++ b/templates/layout.jinja @@ -0,0 +1,57 @@ + + + + + {% if not g.is_mobile %} + {% block js %} + + + {% endblock %} + {% endif %} + + {{ title or "Kostenverwaltung" }} + {% block style %} + + {% endblock %} + + + +
+ + + +
+ +
+
+

{% block heading -%}{%- endblock %}

+ {% block content %}{% endblock %} +
+
+
+ + + diff --git a/templates/macros.jinja b/templates/macros.jinja new file mode 100644 index 0000000..9a9f9af --- /dev/null +++ b/templates/macros.jinja @@ -0,0 +1,35 @@ +{# functions #} +{% macro left_arrow(target,label) %} + + + {{label}} + +{% endmacro %} + +{% macro right_arrow(target,label) %} + + + {{label}} + +{% endmacro %} + +{% macro colorize(fgcolor=None, bgcolor=None, tag='span') -%} + {% if not fgcolor and not bgcolor %} + {{ caller() }} + {% else %} + {% set style = "" %} + {% if fgcolor: %}{% set style = style ~ " color: " ~ fgcolor %}{% endif %} + {% if bgcolor: %}{% set style = style ~ " background: " ~ bgcolor %}{% endif %} + <{{tag}} style="{{style}}">{{caller()}} + {% endif %} +{% endmacro %} + +{% macro render_form(form) %} + + {% for field in form if not field is hidden %} + + + {% endfor %} +
{{ field.label }}{{ field }}{{ field.description }}{% if field.errors %}{{ field.errors[0] }}{% endif %}
+ {{ form.hidden_tag() }} +{% endmacro %} diff --git a/templates/menu.jinja b/templates/menu.jinja index bf7045a..9950c96 100644 --- a/templates/menu.jinja +++ b/templates/menu.jinja @@ -1,7 +1,7 @@ {% set menu = [ ("index", "Kosten"), ("expenses.add", "Neu"), - ("consts.all", "Konstante Kosten"), - ("categories.all", "Kategorien") + ("consts.list", "Konstante Kosten"), + ("categories.manage", "Kategorien") ] %} diff --git a/templates/page.jinja b/templates/page.jinja deleted file mode 100644 index c09dcde..0000000 --- a/templates/page.jinja +++ /dev/null @@ -1,37 +0,0 @@ -{% extends "root.jinja" %} - -{# functions #} -{% macro left_arrow(target,label) %} - - - {{label}} - -{% endmacro %} - -{% macro right_arrow(target,label) %} - - - {{label}} - -{% endmacro %} - -{% macro colorize(fgcolor=None, bgcolor=None, tag='span') -%} - {% if not fgcolor and not bgcolor %} - {{ caller() }} - {% else %} - {% set style = "" %} - {% if fgcolor: %}{% set style = style ~ " color: " ~ fgcolor %}{% endif %} - {% if bgcolor: %}{% set style = style ~ " background: " ~ bgcolor %}{% endif %} - <{{tag}} style="{{style}}">{{caller()}} - {% endif %} -{% endmacro %} - -{% macro render_form(form) %} - - {% for field in form if not field is hidden %} - - - {% endfor %} -
{{ field.label }}{{ field }}{{ field.description }}{% if field.errors %}{{ field.errors[0] }}{% endif %}
- {{ form.hidden_tag() }} -{% endmacro %} diff --git a/templates/pages/add.jinja b/templates/pages/add.jinja deleted file mode 100644 index 4728e99..0000000 --- a/templates/pages/add.jinja +++ /dev/null @@ -1,25 +0,0 @@ -{% extends "page.jinja" %} - -{% block heading %} - Neue Ausgabe hinzufügen -{% endblock %} - -{% block js %} - {{ super() }} - - -{% endblock %} - -{% block style %} - {{ super() }} - -{% endblock %} - -{% block content %} -
- {{ render_form(form) }} - {% block form_buttons %} - - {% endblock %} -
-{% endblock %} diff --git a/templates/pages/cats.jinja b/templates/pages/cats.jinja deleted file mode 100644 index 1a3d88e..0000000 --- a/templates/pages/cats.jinja +++ /dev/null @@ -1,22 +0,0 @@ -{% extends "page.jinja" %} - -{% block heading %} Kategorien {% endblock %} - -{% block js %} - {{ super() }} - -{% endblock %} - -{% block content %} -
-
    - {% for c in cats %} -
  • {{c.name}}
  • - {%- endfor %} -
    -
- -
- -{% endblock %} - diff --git a/templates/pages/const.jinja b/templates/pages/const.jinja deleted file mode 100644 index 13e8008..0000000 --- a/templates/pages/const.jinja +++ /dev/null @@ -1,39 +0,0 @@ -{% extends "page.jinja" %} - -{% set fmt="%m.%Y" %} - -{% block heading %} - Konstante Kosten -{% endblock %} - -{% block content %} -
    -
  • Beschreibung: {{exp.description}}
  • -
  • Kategorie: {{exp.category.name}}
  • -
  • Betrag: {{exp.expense | eur}}
  • -
  • Betrag pro Monat: {{exp.monthly | eur}}
  • -
  • Start: {{exp.start | date(format=fmt)}}
  • -
  • Ende: {{exp.end | date(format=fmt)}}
  • -
  • Zahlungsrhythmus: - {% if exp.months == 1 %} - monatlich - {% elif exp.months == 6 %} - halbjährlich - {% elif exp.months == 12 %} - jährlich - {% else %} - alle {{exp.months}} Monate - {% endif %} -
-

- Bearbeiten  - Erstelle neuen auf dem jetzigen basierenden Eintrag -

- {% if exp.prev %} {{ left_arrow(url_for(".show", id = exp.prev.id), target(exp.prev)) }} {% endif %} - {% if exp.next %} {{ right_arrow(url_for(".show", id = exp.next.id), target(exp.next)) }} {% endif %} -{% endblock %} - -{% macro target(p) -%} - {{ p.description }} ({{ p.start | date(fmt) ~ "-" ~ p.end | date(fmt) }})
- {{ p.expense | eur }} -{%- endmacro %} diff --git a/templates/pages/constadd.jinja b/templates/pages/constadd.jinja deleted file mode 100644 index 8f878b4..0000000 --- a/templates/pages/constadd.jinja +++ /dev/null @@ -1,12 +0,0 @@ -{% extends "page.jinja" %} - -{% block heading %} - Füge neue konstante Ausgabe hinzu -{% endblock %} - -{% block content %} -
- {{ render_form(form) }} - -
-{% endblock %} diff --git a/templates/pages/constedit.jinja b/templates/pages/constedit.jinja deleted file mode 100644 index c440ecb..0000000 --- a/templates/pages/constedit.jinja +++ /dev/null @@ -1,13 +0,0 @@ -{% extends "page.jinja" %} - -{% block heading %} - Konstante Ausgabe bearbeiten -{% endblock %} - -{% block content %} -
- {{ render_form(form) }} - - -
-{% endblock %} diff --git a/templates/pages/constlist.jinja b/templates/pages/constlist.jinja deleted file mode 100644 index ffe121f..0000000 --- a/templates/pages/constlist.jinja +++ /dev/null @@ -1,23 +0,0 @@ -{% extends "page.jinja" %} - -{% block heading %} - Konstante Kosten -{% endblock %} - -{% block content %} -

Neuen Eintrag hinzufügen

- - {{ list(current, "Aktuell") }} - - {% if future %} {{ list(future, "Zukünftige") }} {% endif %} - {% if old %} {{ list(old, "Veraltet") }} {% endif %} -{% endblock %} - -{% macro list(list, h) %} -

{{ h }}

- -{% endmacro %} diff --git a/templates/pages/edit.jinja b/templates/pages/edit.jinja deleted file mode 100644 index c1f4d5b..0000000 --- a/templates/pages/edit.jinja +++ /dev/null @@ -1,10 +0,0 @@ -{% extends "pages/add.jinja" %} - -{% block heading %} - Bearbeite Kosteneintrag -{% endblock %} - -{% block form_buttons %} - - -{% endblock %} diff --git a/templates/pages/show.jinja b/templates/pages/show.jinja deleted file mode 100644 index 4b5170f..0000000 --- a/templates/pages/show.jinja +++ /dev/null @@ -1,62 +0,0 @@ -{% extends "page.jinja" %} - -{% block heading %} - {% if exps | length > 1 %} - Aktuelle Kosten - {% else %} - Kosten für {{exps[0]|date}} - {% endif %} -{% endblock %} - -{% block js %} - {{ super() }} - -{% endblock %} - -{% block content %} - {% for e in exps %} - {% if exps | length > 1 %}

{{e|date}}

{% endif %} - {% for c in e.catexps | sort(attribute="cat.name") %} - {% call(exp) detail(name=c.cat.name, sum=c.expense, set=c.all) %} - {{exp.day}}.{{exp.month}}. -- {{exp.description}}: {{exp.expense | eur }} - {% endcall %} - {% endfor %} - - {% call(exp) detail(name="Constant", sum=e.constsum, set=e.consts) %} - {{exp.monthly}} -- {{exp.description}} - {% endcall %} - - {% call(exp) detail(name="In Summa", sum=e.sum, set=e.all, color="#ff2d2d") %} - {{exp.day}}.{{exp.month}}. -- {{exp.description}}: {{exp.expense | eur}} - {% endcall %} -
- {% endfor %} - - {# Note: exps are given _reversed_, i.e. "exps | last" is - the _first_ on the timeline #} - {% set d = exps | last | prev_date | date %} - {{ left_arrow(url_for(".show_date_str", p = d), d) }} - - {% set first = exps | first %} - {% if not first is last_date %} - {% set d = first | next_date | date %} - {{ right_arrow(url_for(".show_date_str", p = d), d) }} - {% endif %} -{% endblock content %} - -{% macro detail(name, sum, set, color=None) %} -
- - {% call colorize(fgcolor=color) %} - {{name}}: {{sum | eur}}
- {% endcall %} -
-
    - {% for exp in set %} -
  • {{ caller(exp) }}
  • - {% endfor %} -
-
-
-{% endmacro %} - diff --git a/templates/root.jinja b/templates/root.jinja deleted file mode 100644 index dcddc33..0000000 --- a/templates/root.jinja +++ /dev/null @@ -1,57 +0,0 @@ - - - - - {% if not g.is_mobile %} - {% block js %} - - - {% endblock %} - {% endif %} - - {{ title or "Kostenverwaltung" }} - {% block style %} - - {% endblock %} - - - -
- - - -
- -
-
-

{% block heading -%}{%- endblock %}

- {% block content %}{% endblock %} -
-
-
- - - -- cgit v1.2.3