mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Split incoming and former deliveries in home page
This commit is contained in:
parent
f5484bb90a
commit
e0b182dff7
4 changed files with 33 additions and 10 deletions
|
@ -151,7 +151,7 @@ async def set_sesame(request, response, token):
|
||||||
@app.route("/", methods=["GET"])
|
@app.route("/", methods=["GET"])
|
||||||
@auth_required
|
@auth_required
|
||||||
async def home(request, response):
|
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"])
|
@app.route("/livraison", methods=["GET"])
|
||||||
|
|
|
@ -139,6 +139,10 @@ class Delivery(Base):
|
||||||
def is_open(self):
|
def is_open(self):
|
||||||
return datetime.now().date() <= self.order_before.date()
|
return datetime.now().date() <= self.order_before.date()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_foreseen(self):
|
||||||
|
return datetime.now().date() <= self.from_date.date()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def init_fs(cls):
|
def init_fs(cls):
|
||||||
cls.get_root().mkdir(parents=True, exist_ok=True)
|
cls.get_root().mkdir(parents=True, exist_ok=True)
|
||||||
|
@ -159,6 +163,14 @@ class Delivery(Base):
|
||||||
for path in cls.get_root().glob("*.yml"):
|
for path in cls.get_root().glob("*.yml"):
|
||||||
yield Delivery.load(path.stem)
|
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):
|
def persist(self):
|
||||||
with self.__lock__:
|
with self.__lock__:
|
||||||
path = self.get_root() / f"{self.id}.yml"
|
path = self.get_root() / f"{self.id}.yml"
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h2>Livraisons à venir</h2>
|
<h2>Livraisons à venir</h2>
|
||||||
<ul class="delivery">
|
{% with deliveries=incoming %}
|
||||||
{% for delivery in deliveries %}
|
{% include "includes/delivery_list.html" %}
|
||||||
<li>
|
{% endwith %}
|
||||||
<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>
|
<h2>Livraisons passées</h2>
|
||||||
{% include "includes/delivery_head.html" %}
|
{% with deliveries=former %}
|
||||||
</li>
|
{% include "includes/delivery_list.html" %}
|
||||||
<hr>
|
{% endwith %}
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
|
13
copanier/templates/includes/delivery_list.html
Normal file
13
copanier/templates/includes/delivery_list.html
Normal 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 %}
|
Loading…
Reference in a new issue