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 %}
Aucune livraison.
+{% endif %}