From 28cd6947a59da498ea648f29ab02f3679a57ce4e Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Sat, 28 Mar 2015 23:06:36 +0100 Subject: [PATCH] Added some layouting --- app/models.py | 6 ++++++ app/static/css/main.css | 18 +++++++++++++++++- app/templates/home.html | 18 +++++++++--------- app/templates/order.html | 38 ++++++++++++++++++++++++++------------ app/templates/orders.html | 13 +++++++------ app/templates/utils.html | 12 ++++++++++++ app/utils.py | 10 ++++++++++ app/views/order.py | 7 ++++--- 8 files changed, 91 insertions(+), 31 deletions(-) create mode 100644 app/templates/utils.html diff --git a/app/models.py b/app/models.py index 625ed40..955b359 100644 --- a/app/models.py +++ b/app/models.py @@ -104,6 +104,12 @@ class Order(db.Model): group[item.get_name()] += item.product.price return group + def group_by_product(self): + group = defaultdict(int) + for item in self.items: + group[item.product.name] += 1 + return group + def can_close(self, user_id): if self.stoptime and self.stoptime < datetime.now(): return False diff --git a/app/static/css/main.css b/app/static/css/main.css index 482ef88..34bf47a 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -1,4 +1,20 @@ /* Custom CSS */ body { padding-top: 70px; -} \ No newline at end of file +} + +.darker { + background-color: #fafafa; + margin-top: 10px; + padding-bottom: 5px; +} + +@media (min-width: 992px) { + .align-bottom { + margin-top: 2.5em; + } +} + +.full-width { + width: 100%; +} diff --git a/app/templates/home.html b/app/templates/home.html index c280c45..0c0f681 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -1,5 +1,8 @@ {% extends "layout.html" -%} {% set active_page = "home" -%} + +{% import "utils.html" as util -%} + {% block container %}

Welcome to FoodBot

@@ -8,18 +11,15 @@

Open orders:

- + {% for order in orders %} + {{ util.render_order(order) }} + {% endfor %}

Recently closed orders:

-
diff --git a/app/templates/order.html b/app/templates/order.html index 694652f..4828327 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -4,35 +4,49 @@ {% import "bootstrap/wtf.html" as wtf %} {% block container %}
-
+

Order {{ order.id }} {% if order.can_close(current_user.id) -%} Close
{%- endif %}

Courrier: {{ order.courrier.username }} {% if order.courrier == None and not current_user.is_anonymous() %} - Volunteer + Volunteer {% endif %}
Location: {{ order.location.name }}
Starttime: {{ order.starttime }}
Stoptime: {{ order.stoptime }}
Total price: {{ total_price|euro }} -

Orders

- {% for item in order.items %} - {{ item.get_name() }} - {{ item.product.name }} - {{ item.product.price|euro }} - {% if item.can_delete(order.id, current_user.id, session.get('anon_name', '')) -%}{%- endif %}
- {% endfor %} -

Debts

- {% for key, value in total_payments.items() %} - {{ key }} - {{ value|euro }}
- {% endfor %}
{% if form -%} -
+

Order:

{{ wtf.quick_form(form, action=url_for('.order_item_create', id=order.id), button_map={'submit_button': 'primary'}, form_type='horizontal') }}
{%- endif %}
+
+
+

Orders

+ {% for item in order.items %} + {{ item.get_name() }} - {{ item.product.name }} - {{ item.product.price|euro }} + {% if item.can_delete(order.id, current_user.id, session.get('anon_name', '')) -%}{%- endif %}
+ {% endfor %} +
+
+

Ordered products:

+ {% for key, value in order.group_by_product().items() %} + {{ key }} - {{ value }}
+ {% endfor %} +
+
+
+
+

Debts

+ {% for key, value in order.group_by_user_pay().items() %} + {{ key }} - {{ value|euro }}
+ {% endfor %} +
+
{% endblock %} \ No newline at end of file diff --git a/app/templates/orders.html b/app/templates/orders.html index 6cab482..2374341 100644 --- a/app/templates/orders.html +++ b/app/templates/orders.html @@ -2,19 +2,20 @@ {% set active_page = "orders" -%} {% import "bootstrap/wtf.html" as wtf %} +{% import "utils.html" as util -%} + {% block container %}

Open orders:

- + {% for order in orders %} + {{ util.render_order(order) }} + {% endfor %}
{% if not current_user.is_anonymous() %}
- {{ wtf.quick_form(form, action=url_for('.order_create'), button_map={'submit_button': 'primary'}, form_type='horizontal') }} +

Create new order:

+ {{ wtf.quick_form(form, action=url_for('.order_create'), button_map={'submit_button': 'primary'}, form_type='horizontal') }}
{% endif %}
diff --git a/app/templates/utils.html b/app/templates/utils.html new file mode 100644 index 0000000..98ce6a4 --- /dev/null +++ b/app/templates/utils.html @@ -0,0 +1,12 @@ +{% macro render_order(order) -%} +
+
+
{{ order.location.name }}
+

Status: {{ order.stoptime|countdown }}
+ Orders: {{ order.items.count() }}

+
+
+ Open +
+
+{%- endmacro %} \ No newline at end of file diff --git a/app/utils.py b/app/utils.py index 0aff1fe..afa84ff 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,3 +1,4 @@ +from datetime import datetime from flask import render_template from app import app @@ -10,6 +11,15 @@ def euro(value): result = '€' + str(value/100) return result +@app.template_filter('countdown') +def countdown(value): + delta = value - datetime.now() + if delta.total_seconds() < 0: + return "closed" + hours, remainder = divmod(delta.seconds, 3600) + minutes, seconds = divmod(remainder, 60) + return 'closes in %02d:%02d:%02d' % (hours, minutes, seconds) + @app.errorhandler(404) def handle404(e): return render_template('errors/404.html'), 404 diff --git a/app/views/order.py b/app/views/order.py index 91bb2f6..81ff2b1 100644 --- a/app/views/order.py +++ b/app/views/order.py @@ -48,8 +48,7 @@ def order(id): if order.stoptime and order.stoptime < datetime.now(): form = None total_price = sum([o.product.price for o in order.items]) - total_payments = order.group_by_user_pay() - return render_template('order.html', order=order, form=form, total_price=total_price, total_payments=total_payments) + return render_template('order.html', order=order, form=form, total_price=total_price) @order_bp.route('//create', methods=['GET', 'POST']) @@ -143,8 +142,10 @@ def select_user(items): return user -def get_orders(expression=(Order.stoptime > datetime.now()) | (Order.stoptime == None)): +def get_orders(expression=None): orders = [] + if expression is None: + expression = (Order.stoptime > datetime.now()) | (Order.stoptime == None) if not current_user.is_anonymous(): orders = Order.query.filter(expression).all() else: