Edit orders
This commit is contained in:
parent
3aa16e2690
commit
50a8714c51
3 changed files with 97 additions and 1 deletions
|
@ -9,6 +9,7 @@
|
|||
<h3>Order {{ order.id }}
|
||||
{% if order.can_close(current_user.id) -%}
|
||||
<a class="btn btn-danger pull-right" href="{{ url_for('.close_order', id=order.id) }}">Close</a><br/>
|
||||
<a class="btn btn-warning pull-right" href="{{ url_for('.order_edit', id=order.id) }}">Edit</a>
|
||||
{%- endif %}</h3>
|
||||
courier: {{ order.courrier.username }}
|
||||
{% if order.courrier == None and not current_user.is_anonymous() %}
|
||||
|
|
79
app/templates/order_edit.html
Normal file
79
app/templates/order_edit.html
Normal file
|
@ -0,0 +1,79 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% set active_page = "orders" -%}
|
||||
|
||||
{% import "bootstrap/wtf.html" as wtf %}
|
||||
{% import "utils.html" as util -%}
|
||||
|
||||
{% block container %}
|
||||
<div class="row">
|
||||
{% if not current_user.is_anonymous() %}
|
||||
<div class="col-md-push-4 col-md-6">
|
||||
<h3>Create new order:</h3>
|
||||
<div class="row darker">
|
||||
<div class="col-sm-12">
|
||||
<form method="post" action="{{ url_for('.order_edit', id=order_id) }}">
|
||||
{{ form.csrf_token }}
|
||||
<div class="form-group select2 {{ 'has-errors' if form.courrier_id.errors else ''}}">
|
||||
{{ form.courrier_id.label(class='control-label') }}<br>
|
||||
{{ form.courrier_id(class='form-control select') }}
|
||||
{{ util.render_form_field_errors(form.courrier_id) }}
|
||||
</div>
|
||||
<div class="form-group select2 {{ 'has-errors' if form.location_id.errors else ''}}{{ ' required' if form.location_id.flags.required }}">
|
||||
{{ form.location_id.label(class='control-label') }}
|
||||
{{ form.location_id(class='form-control select') }}
|
||||
{{ util.render_form_field_errors(form.location_id) }}
|
||||
</div>
|
||||
{% if current_user.is_admin() %}
|
||||
<div class="form-group{{ ' has-error' if form.starttime.errors }}{{ ' required' if form.starttime.flags.required }}{{ ' hidden' if not current_user.is_admin() }}">
|
||||
{{ form.starttime.label(class='control-label') }}
|
||||
<div class='input-group date' class='datetimepicker'>
|
||||
{{ form.starttime(class='form-control datetimepicker') }}
|
||||
<span class="input-group-addon">
|
||||
<span class="glyphicon glyphicon-calendar"></span>
|
||||
</span>
|
||||
</div>
|
||||
{{ util.render_form_field_errors(form.starttime) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="form-group{{ ' has-error' if form.stoptime.errors }}{{ ' required' if form.stoptime.flags.required }}{{ ' hidden' if not current_user.is_admin() }}">
|
||||
{{ form.stoptime.label(class='control-label') }}
|
||||
<div class='input-group date' class='datetimepicker'>
|
||||
{{ form.stoptime(class='form-control datetimepicker') }}
|
||||
<span class="input-group-addon">
|
||||
<span class="glyphicon glyphicon-calendar"></span>
|
||||
</span>
|
||||
</div>
|
||||
{{ util.render_form_field_errors(form.stoptime) }}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.submit_button(class='btn btn-primary') }}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block styles -%}
|
||||
{{ super() }}
|
||||
<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-rc.2/css/select2.min.css" rel="stylesheet" />
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-datetimepicker.min.css') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/select2-bootstrap.min.css') }}">
|
||||
{%- endblock %}
|
||||
{% block scripts -%}
|
||||
{{ super() }}
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-rc.2/js/select2.min.js"></script>
|
||||
<script src="{{ url_for('static', filename='js/moment.min.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/bootstrap-datetimepicker.min.js') }}"></script>
|
||||
<script type="text/javascript">
|
||||
$.ready(function(){
|
||||
$('.select').select2();
|
||||
$('.datetimepicker').datetimepicker({
|
||||
format: 'DD-MM-YYYY HH:mm'
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
{%- endblock %}
|
|
@ -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('/<id>/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('/<id>/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('/<order_id>/<item_id>/delete')
|
||||
def delete_item(order_id, item_id):
|
||||
item = OrderItem.query.filter(OrderItem.id == item_id).first()
|
||||
|
|
Loading…
Reference in a new issue