From e0b182dff79474a2b4c9e88caf501514c918d315 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sun, 24 Mar 2019 20:23:54 +0100 Subject: [PATCH] Split incoming and former deliveries in home page --- copanier/__init__.py | 2 +- copanier/models.py | 12 ++++++++++++ copanier/templates/home.html | 16 +++++++--------- copanier/templates/includes/delivery_list.html | 13 +++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 copanier/templates/includes/delivery_list.html diff --git a/copanier/__init__.py b/copanier/__init__.py index 914f4bd..4d9ffe5 100644 --- a/copanier/__init__.py +++ b/copanier/__init__.py @@ -151,7 +151,7 @@ async def set_sesame(request, response, token): @app.route("/", methods=["GET"]) @auth_required async def home(request, response): - response.html("home.html", deliveries=Delivery.all()) + response.html("home.html", incoming=Delivery.incoming(), former=Delivery.former()) @app.route("/livraison", methods=["GET"]) diff --git a/copanier/models.py b/copanier/models.py index 79b010d..6c51f0c 100644 --- a/copanier/models.py +++ b/copanier/models.py @@ -139,6 +139,10 @@ class Delivery(Base): def is_open(self): return datetime.now().date() <= self.order_before.date() + @property + def is_foreseen(self): + return datetime.now().date() <= self.from_date.date() + @classmethod def init_fs(cls): cls.get_root().mkdir(parents=True, exist_ok=True) @@ -159,6 +163,14 @@ class Delivery(Base): for path in cls.get_root().glob("*.yml"): yield Delivery.load(path.stem) + @classmethod + def incoming(cls): + return [d for d in cls.all() if d.is_foreseen] + + @classmethod + def former(cls): + return [d for d in cls.all() if not d.is_foreseen] + def persist(self): with self.__lock__: path = self.get_root() / f"{self.id}.yml" diff --git a/copanier/templates/home.html b/copanier/templates/home.html index 9f91411..d08ae7a 100644 --- a/copanier/templates/home.html +++ b/copanier/templates/home.html @@ -1,13 +1,11 @@ {% extends "base.html" %} {% block body %}

Livraisons à venir

- + {% with deliveries=incoming %} + {% include "includes/delivery_list.html" %} + {% endwith %} +

Livraisons passées

+ {% with deliveries=former %} + {% include "includes/delivery_list.html" %} + {% endwith %} {% endblock body %} diff --git a/copanier/templates/includes/delivery_list.html b/copanier/templates/includes/delivery_list.html new file mode 100644 index 0000000..37291ce --- /dev/null +++ b/copanier/templates/includes/delivery_list.html @@ -0,0 +1,13 @@ +{% if deliveries %} + +{% else %} +

Aucune livraison.

+{% endif %}