diff --git a/app/templates/order.html b/app/templates/order.html index 852687c..0d9821c 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -11,6 +11,7 @@

Order {{ order.id }} {% if courier_or_admin -%} 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 2e9a07b..b009142 100644 --- a/app/views/order.py +++ b/app/views/order.py @@ -1,6 +1,6 @@ __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 @@ -51,6 +51,20 @@ def order(id, form=None): return render_template('order.html', order=order, form=form, total_price=total_price, debts=debts) +@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()