ciclos

commit 70d40d8d0ed7506b45124c459369c48070748ce3

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

Add a cycles page and allow user to see one cycle

When user open a cycle page, it should prompt the user to create his
order. And then reload the page with the `current_order` variable set in
the session, which ultimatelly would point to the last order from that
consumer/user.

 src/blueprints/cycles.py | 13 +++++++++++
 src/templates/cycle.html | 43 +++++++++++++++++++++++++++++++++++++++++
 src/templates/cycles.html | 8 +++++++


diff --git a/src/blueprints/cycles.py b/src/blueprints/cycles.py
index bed6f06f9a44bdcb8de4fd3269977195354795c8..77c3221522a1303f69de0ecdf119c1dcaae12843 100644
--- a/src/blueprints/cycles.py
+++ b/src/blueprints/cycles.py
@@ -3,11 +3,13 @@
 cycles = Blueprint('cycles', __name__, url_prefix = '/cycles')
 
 from ..types.cycle import Cycle, CycleStatus
+from ..types.product import Product
 
 @cycles.route('/', methods = ['GET', 'POST'])
 def index():
     if request.method == 'GET':
-        return 'yo'
+        current_cycle = Cycle.query.filter_by(status = 'published').first()
+        return render_template('cycles.html', current_cycle = current_cycle, title = "Ciclos - Feira Virtual Bem da Terra")
     else:
         return create(request.form)
 
@@ -15,6 +17,15 @@ @cycles.route('/new', methods = ['GET'])
 def new():
     cycle_status_options = [(cycle.value, cycle.name) for cycle in CycleStatus]
     return render_template('new_cycle.html', cycles = cycle_status_options, title = "Abrir novo Ciclo - Feira Virtual Bem da Terra")
+
+@cycles.route('/<id>', methods = ['GET'])
+def show(id):
+    cycle = Cycle.query.filter_by(id = id).first()
+    products = Product.query.all()
+    if not cycle:
+        return "Not found", 404
+
+    return render_template('cycle.html', cycle = cycle, products = products, title = "Carrinho - Feira Virtual")
 
 def create(params):
     start_at = params.get('start_at')




diff --git a/src/templates/cycle.html b/src/templates/cycle.html
new file mode 100644
index 0000000000000000000000000000000000000000..3e1e9c47722b29456546023eac9c9051b3700158
--- /dev/null
+++ b/src/templates/cycle.html
@@ -0,0 +1,43 @@
+<section class="a">
+  <h1>{{ cycle.name }}</h1>
+  <em>{{ cycle.description }}</em>
+  <section class="products">
+    <form action="" method="post">
+      <table>
+        <thead>
+          <tr>
+            <th></th>
+            <th>Nome do Produto</th>
+            <th>Grupo</th>
+            <th>Categoria</th>
+          </tr>
+        </thead>
+        <tbody>
+          {% for product in products %}
+            <tr>
+              <td> <input type="checkbox" name="product_ids" > </td>
+              <td> {{ product.title }} </td>
+              <td> {{ product.group.name }} </td>
+              <td> {{ product.category.name }}</td>
+            </tr>
+          {% endfor %}
+        </tbody>
+      </table>
+
+      <section>
+        <h4> O que vocĂȘ vai levar: </h4>
+        <ul>
+          <li>Cebola - Grupo Germinari - 2</li>
+        </ul>
+        
+        <div style="text-align: left;">
+          Total: <em>R$ 19,17</em>
+        </div>
+      </section>
+
+      <div class="form-action">
+        <button type="submit" rel="button">Confirmar produtos</button>
+      </div>
+    </form> 
+  </section>
+</section>




diff --git a/src/templates/cycles.html b/src/templates/cycles.html
new file mode 100644
index 0000000000000000000000000000000000000000..bf6a5fcd2bc05dbb18ebbc40db48e7f85f4b0098
--- /dev/null
+++ b/src/templates/cycles.html
@@ -0,0 +1,8 @@
+<section class="cycles">
+  <h1>Ciclo em aberto</h1>
+  <div class="cycle">
+    <h2>{{ current_cycle.title }}</h2>
+    <p>{{ current_cycle.description }}</p>
+    <a href="{{url_for('cycles.show', id = current_cycle.id)}}">Ver ciclo</a> 
+  </div>
+</section>