From d5c4984fda9819e84c8c97979f95e5b5cc5e2eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Sat, 30 Apr 2016 22:29:46 +0200 Subject: current_expenses --- app/model.py | 17 ++++++++++++++++- templates/consts/list.jinja | 10 ++++++---- templates/consts/show.jinja | 4 ++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/model.py b/app/model.py index 248647c..4f80b85 100644 --- a/app/model.py +++ b/app/model.py @@ -143,7 +143,10 @@ class ConstExpenseGroup (UserModel, CategoryModel): start = ReqColumn(db.Date, index = True) end = ReqColumn(db.Date, index = True) - expenses = db.relationship("ConstExpense", back_populates = "group") + expenses = db.relationship("ConstExpense", back_populates = "group", order_by = 'desc(ConstExpense.end)') + + def current_expenses(self): + return filter(ConstExpense.is_current, self.expenses) class ConstExpense (UserModel, CategoryModel): description = Column(db.Unicode(50)) @@ -168,6 +171,18 @@ class ConstExpense (UserModel, CategoryModel): d = datetime.date(year, month, 1) return cls.of(user).filter(sql.between(d, cls.start, cls.end)) + def _today(self): + return datetime.date.today().replace(day = 1) + + def is_current(self): + return self.start <= self._today() <= self.end + + def is_future(self): + return self.start > self._today() + + def is_expired(self): + return self.end < self._today() + # # Work entities (not stored in DB) # diff --git a/templates/consts/list.jinja b/templates/consts/list.jinja index 7fef344..80d22ad 100644 --- a/templates/consts/list.jinja +++ b/templates/consts/list.jinja @@ -7,18 +7,20 @@ {% block content %}

Neuen Eintrag hinzufügen

- {{ list(current, "Aktuell") }} + {{ list(current, "Aktuell", True) }} {% if last_month %} {{ list(last_month, "Endeten letzten Monat") }} {% endif %} {% if future %} {{ list(future, "Zukünftige") }} {% endif %} {% if old %} {{ list(old, "Veraltet") }} {% endif %} {% endblock %} -{% macro list(list, h) %} +{% macro list(list, h, use_current = False) %}

{{ h }}

{% endmacro %} diff --git a/templates/consts/show.jinja b/templates/consts/show.jinja index c09fc3b..5ae5319 100644 --- a/templates/consts/show.jinja +++ b/templates/consts/show.jinja @@ -3,12 +3,12 @@ {% set fmt="%m.%Y" %} {% block heading %} - Konstante Kosten + Konstante Kosten: {{ exp.group.description }} {% endblock %} {% block content %}