Split incoming and former deliveries in home page

This commit is contained in:
Yohan Boniface 2019-03-24 20:23:54 +01:00
parent f5484bb90a
commit e0b182dff7
4 changed files with 33 additions and 10 deletions

View file

@ -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"])

View file

@ -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"

View file

@ -1,13 +1,11 @@
{% extends "base.html" %}
{% block body %}
<h2>Livraisons à venir</h2>
<ul class="delivery">
{% for delivery in deliveries %}
<li>
<h3><a href="/livraison/{{ delivery.id }}"><i class="icon-hotairballoon"></i> {{ delivery.producer }}</a> {% if delivery.is_open %}<a class="button" href="/livraison/{{ delivery.id }}/commander">Gérer ma commande</a>{% endif %}</h3>
{% include "includes/delivery_head.html" %}
</li>
<hr>
{% endfor %}
</ul>
{% with deliveries=incoming %}
{% include "includes/delivery_list.html" %}
{% endwith %}
<h2>Livraisons passées</h2>
{% with deliveries=former %}
{% include "includes/delivery_list.html" %}
{% endwith %}
{% endblock body %}

View file

@ -0,0 +1,13 @@
{% if deliveries %}
<ul class="delivery">
{% for delivery in deliveries %}
<li>
<h3><a href="/livraison/{{ delivery.id }}"><i class="icon-hotairballoon"></i> {{ delivery.producer }}</a> {% if delivery.is_open %}<a class="button" href="/livraison/{{ delivery.id }}/commander">Gérer ma commande</a>{% endif %}</h3>
{% include "includes/delivery_head.html" %}
</li>
<hr>
{% endfor %}
</ul>
{% else %}
<p>Aucune livraison.</p>
{% endif %}