From 50a8714c5177608169b2d2ff8b94f27ef67cc2c3 Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Thu, 4 Jun 2015 19:11:08 +0200 Subject: [PATCH] Edit orders --- app/templates/order.html | 1 + app/templates/order_edit.html | 79 +++++++++++++++++++++++++++++++++++ app/views/order.py | 18 +++++++- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 app/templates/order_edit.html diff --git a/app/templates/order.html b/app/templates/order.html index c918635..7e7cbbf 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -9,6 +9,7 @@

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

courier: {{ order.courrier.username }} {% if order.courrier == None and not current_user.is_anonymous() %} diff --git a/app/templates/order_edit.html b/app/templates/order_edit.html new file mode 100644 index 0000000..84a68d6 --- /dev/null +++ b/app/templates/order_edit.html @@ -0,0 +1,79 @@ +{% extends 'layout.html' %} +{% set active_page = "orders" -%} + +{% import "bootstrap/wtf.html" as wtf %} +{% import "utils.html" as util -%} + +{% block container %} +
+ {% if not current_user.is_anonymous() %} +
+

Create new order:

+
+
+
+ {{ form.csrf_token }} +
+ {{ form.courrier_id.label(class='control-label') }}
+ {{ form.courrier_id(class='form-control select') }} + {{ util.render_form_field_errors(form.courrier_id) }} +
+
+ {{ form.location_id.label(class='control-label') }} + {{ form.location_id(class='form-control select') }} + {{ util.render_form_field_errors(form.location_id) }} +
+ {% if current_user.is_admin() %} +
+ {{ form.starttime.label(class='control-label') }} +
+ {{ form.starttime(class='form-control datetimepicker') }} + + + +
+ {{ util.render_form_field_errors(form.starttime) }} +
+ {% endif %} +
+ {{ form.stoptime.label(class='control-label') }} +
+ {{ form.stoptime(class='form-control datetimepicker') }} + + + +
+ {{ util.render_form_field_errors(form.stoptime) }} +
+
+ {{ form.submit_button(class='btn btn-primary') }} +
+
+
+
+
+ {% endif %} +
+ +{% endblock %} + +{% block styles -%} + {{ super() }} + + + +{%- endblock %} +{% block scripts -%} + {{ super() }} + + + + +{%- endblock %} \ No newline at end of file diff --git a/app/views/order.py b/app/views/order.py index b8089d0..de92b92 100644 --- a/app/views/order.py +++ b/app/views/order.py @@ -1,5 +1,5 @@ __author__ = 'feliciaan' -from flask import url_for, render_template, abort, redirect, Blueprint, flash, session +from flask import url_for, render_template, abort, redirect, Blueprint, flash, session, request from flask.ext.login import current_user, login_required import random from datetime import datetime @@ -49,6 +49,20 @@ def order(id, form=None): return render_template('order.html', order=order, form=form, total_price=total_price) +@order_bp.route('//edit', methods=['GET', 'POST']) +@login_required +def order_edit(id): + order = Order.query.filter(Order.id == id).first() + if order is None: + abort(404) + orderForm = OrderForm(obj=order) + orderForm.populate() + if orderForm.validate_on_submit(): + orderForm.populate_obj(order) + db.session.commit() + return redirect(url_for('.order', id=order.id)) + return render_template('order_edit.html', form=orderForm, order_id=id) + @order_bp.route('//create', methods=['POST']) def order_item_create(id): current_order = Order.query.filter(Order.id == id).first() @@ -75,6 +89,8 @@ def order_item_create(id): return redirect(url_for('.order', id=id)) return order(id, form=form) + + @order_bp.route('///delete') def delete_item(order_id, item_id): item = OrderItem.query.filter(OrderItem.id == item_id).first()