ciclos

commit 71c408a8758c0d895923cb0c2afe9b12beb351f8

Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>

Display orders

 src/blueprints/orders.py | 11 ++++++++---
 src/templates/orders.html | 25 +++++++++++++++++++++++++
 src/types/order.py | 1 +


diff --git a/src/blueprints/orders.py b/src/blueprints/orders.py
index 40f799c9a5ac0ea9f831f391c89ae67ee93d6558..51c37e47208fbe340fa40d9b926c2be52efaa438 100644
--- a/src/blueprints/orders.py
+++ b/src/blueprints/orders.py
@@ -1,4 +1,4 @@
-from flask import request, redirect, url_for, Blueprint
+from flask import request, redirect, url_for, Blueprint, jsonify, render_template
 from flask_login import current_user
 
 from ..types.cycle import Cycle, CycleStatus
@@ -7,10 +7,15 @@ import pdb
 
 orders = Blueprint('orders', __name__, url_prefix = '/orders')
 
-@orders.route('/')
+@orders.route('/', methods = ['GET', 'POST'])
+def index():
+    orders = Order.query.filter(Order.user.has(id = current_user.id)).order_by(Order.id.desc()).all()
+
+    return render_template('orders.html', orders = orders, title = "Seus Pedidos")
+
+@orders.route('/create')
 def create():
     current_cycle = Cycle.query.filter_by(status = CycleStatus.published).first() 
- 
     if not current_cycle:
         return '', 401
 




diff --git a/src/templates/orders.html b/src/templates/orders.html
new file mode 100644
index 0000000000000000000000000000000000000000..b457ecd13ef3d1f2b5baca9931c1b5c74976442e
--- /dev/null
+++ b/src/templates/orders.html
@@ -0,0 +1,25 @@
+{% extends "layout.html" %}
+{% block body %}
+  <section>
+    <h1> Seus pedidos </h1>
+
+    {% for order in orders %}
+    <div class="order p-5 {{ 'current-cycle' if order.cycle.status.value == "published" }}">
+        Seu pedido no ciclo <strong>{{ order.cycle.name }}</strong>:
+        <div>
+          <small>{{ order.cycle.start_at.strftime("%d/%m/%Y") }} até {{ order.cycle.end_at.strftime("%d/%m/%Y") }}</small>
+        </div>
+        
+        <ul>
+          {% for product in order.products() %}
+            <li>{{ product.title }}</li>
+          {% endfor %}
+        </ul>
+
+        <div class="pt-5 pb-5">
+          <a href="{{url_for('cycles.show', id = order.cycle.id)}}">Ver ciclo</a>
+        </div>
+      </div>
+    {% endfor %}
+  </section>
+{% endblock %}




diff --git a/src/types/order.py b/src/types/order.py
index b30c5bdfd0404f912dc4f36da77f7194cf8b3169..2707f7945738dd9bcfb00556485ed0a4ec79fd60 100644
--- a/src/types/order.py
+++ b/src/types/order.py
@@ -72,6 +72,7 @@         return sum(prices, 0)
 
     def to_json(self):
         return {
+            "id": self.id,
             "user_id": self.user_id,
             "cycle_id": self.cycle_id,
             "products": self.selected_product_ids()