From 6c0badfd55def99cbcdcb0295828e2aa845b6f8b Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Sun, 29 Mar 2015 22:44:26 +0200 Subject: [PATCH] search items --- app/templates/order.html | 4 +--- app/templates/order_form.html | 38 +++++++++++++++++++++++++++++++--- app/templates/orders_form.html | 9 ++++++++ app/templates/utils.html | 12 ++++++++++- app/views/order.py | 4 ++-- 5 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 app/templates/orders_form.html diff --git a/app/templates/order.html b/app/templates/order.html index 2d833d6..a5ee9a7 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -1,7 +1,6 @@ {% extends "layout.html" %} {% set active_page = "orders" -%} -{% import "bootstrap/wtf.html" as wtf %} {% block container %}
@@ -15,14 +14,13 @@ {% endif %}
location: {{ order.location.name }}
- opened on {{ order.starttime }}
status: {% if order.stoptime %}{{ order.stoptime|countdown }}{% else %}open{% endif %}
total price: {{ total_price|euro }}
{% if form -%}

Order:

- {{ wtf.quick_form(form, action=url_for('.order_item_create', id=order.id), button_map={'submit_button': 'primary'}, form_type='horizontal') }} + {% include "order_form.html" with context %}
{%- endif %}
diff --git a/app/templates/order_form.html b/app/templates/order_form.html index a5b5068..f547e43 100644 --- a/app/templates/order_form.html +++ b/app/templates/order_form.html @@ -1,9 +1,41 @@ {% extends "layout.html" %} {% set active_page = "orders" -%} -{% import "bootstrap/wtf.html" as wtf %} -{% block container %} +{% import "utils.html" as util %} + +{% block content %}
- {{ wtf.quick_form(form, action=url, button_map={'submit_button': 'primary'}) }} +
+
+ {{ form.csrf_token }} +
+ {{ form.product_id.label(class='control-label') }} + {{ form.product_id(class='form-control select') }} + {{ util.render_form_field_errors(form.product_id) }} +
+ {% if current_user.is_anonymous() %} +
+ {{ form.name.label(class='control-label') }} + {{ form.name(class='form-control') }} + {{ util.render_form_field_errors(form.name) }} +
+ {% endif %} +
+ {{ form.submit_button(class='btn btn-primary') }} +
+
+
+{% endblock %} + +{% block styles %} + {{ super() }} + +{% endblock %} +{% block scripts %} + {{ super() }} + + {% endblock %} \ No newline at end of file diff --git a/app/templates/orders_form.html b/app/templates/orders_form.html new file mode 100644 index 0000000..a5b5068 --- /dev/null +++ b/app/templates/orders_form.html @@ -0,0 +1,9 @@ +{% extends "layout.html" %} +{% set active_page = "orders" -%} + +{% import "bootstrap/wtf.html" as wtf %} +{% block container %} +
+ {{ wtf.quick_form(form, action=url, button_map={'submit_button': 'primary'}) }} +
+{% endblock %} \ No newline at end of file diff --git a/app/templates/utils.html b/app/templates/utils.html index 6d70c07..bdb0e31 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -9,4 +9,14 @@ Expand -{%- endmacro %} \ No newline at end of file +{%- endmacro %} + +{% macro render_form_field_errors(field) %} +{%- if field.errors %} + {%- for error in field.errors %} +

{{error}}

+ {%- endfor %} +{%- elif field.description -%} +

{{field.description|safe}}

+{%- endif %} +{% endmacro %} \ No newline at end of file diff --git a/app/views/order.py b/app/views/order.py index a57027d..06d6b10 100644 --- a/app/views/order.py +++ b/app/views/order.py @@ -31,7 +31,7 @@ def order_create(): db.session.commit() return redirect(url_for('.order', id=order.id)) - return render_template('order_form.html', form=orderForm, url=url_for(".order_create")) + return render_template('orders_form.html', form=orderForm, url=url_for(".order_create")) @order_bp.route('/') @@ -76,7 +76,7 @@ def order_item_create(id): db.session.commit() flash('Ordered %s' % (item.product.name), 'info') return redirect(url_for('.order', id=id)) - return render_template('order_form.html', form=form, url=url_for(".order_item_create", id=id)) + return render_template('order_form.html', form=form, order=order) @order_bp.route('///delete') def delete_item(order_id, item_id):