Browse Source

deletion of orders working

php2python
Holger Frey 7 years ago
parent
commit
2178f37d6a
  1. 66
      ordr2/templates/orders/delete.jinja2
  2. 2
      ordr2/templates/orders/edit_multiple_stati.jinja2
  3. 58
      ordr2/views/orders.py

66
ordr2/templates/orders/delete.jinja2

@ -0,0 +1,66 @@
{% extends "ordr2:templates/layout.jinja2" %}
{% import 'ordr2:templates/macros.jinja2' as macros with context %}
{% block subtitle %} Orders | Confirm Delete {% endblock subtitle %}
{% block content %}
<div class="content controls">
<div class="container-fluid">
<div class="row-fluid">
<div class="page-controls">
<h1>Delete Order{{ 's' if orders|length > 1 }}</h1>
</div>
</div>
<div class="row">
<div class="span10">
<div class="action-header">
<h3>The following order{{ 's' if orders|length > 1 }} will be deleted:</h3>
</div>
<form action="{{ request.resource_url(context, 'delete') }}" method="POST" class="action">
<input type="hidden" name="csrf_token" value="{{get_csrf_token()}}">
<table class="table">
<thead>
<th>Date Created</th>
<th>CAS / Description</th>
<th>Vendor</th>
<th>Placed by</th>
<th>Status</th>
</thead>
<tbody>
{% for order in orders %}
<tr>
<td>
<input type="hidden" name="order" value="{{ order.id }}">
{{ order.created_date }}
</td>
<td>{{ order.cas_description }} </td>
<td>{{ order.vendor }} </td>
<td>{{ order.created_by }} </td>
<td>{{ macros.colored_status(order.status) }} </td>
</tr>
{% endfor %}
</tbody>
</table>
<fieldset class="form-actions">
<div class="right">
<button name="delete" type="submit" value="submit" class="btn btn-large btn-danger">Delete Order{{ 's' if orders|length > 1 }}</button>
<button name="cancel" type="submit" value="cancel" class="btn btn-large">Cancel</button>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
{% endblock content %}

2
ordr2/templates/orders/edit_multiple_stati.jinja2

@ -27,6 +27,7 @@
<thead> <thead>
<th>Date Created</th> <th>Date Created</th>
<th>CAS / Description</th> <th>CAS / Description</th>
<th>Vendor</th>
<th>Placed by</th> <th>Placed by</th>
<th>Status</th> <th>Status</th>
</thead> </thead>
@ -36,6 +37,7 @@
<tr> <tr>
<td>{{ order.created_date }}</td> <td>{{ order.created_date }}</td>
<td>{{ order.cas_description }} </td> <td>{{ order.cas_description }} </td>
<td>{{ order.vendor }} </td>
<td>{{ order.created_by }} </td> <td>{{ order.created_by }} </td>
<td> <td>
<select name="order-{{ order.id }}" class="select-status span2"> <select name="order-{{ order.id }}" class="select-status span2">

58
ordr2/views/orders.py

@ -110,10 +110,68 @@ def edit_multiple_stati_form_processing(context, request):
return HTTPFound(context.url()) return HTTPFound(context.url())
@view_config(
context='ordr2:resources.OrderList',
name='actions',
request_param='action=delete',
permission='delete',
request_method='POST',
renderer='ordr2:templates/orders/delete.jinja2'
)
def delete_multiple_orders_form(context, request):
order_ids = [v for k, v in request.POST.items() if k == 'marked']
orders = request.dbsession.\
query(Order).\
filter(Order.id.in_(order_ids)).\
order_by(Order.created_date).\
all()
if len(orders) == 0:
return HTTPFound(context.url())
return {'orders': orders}
@view_config(
context='ordr2:resources.OrderList',
name='delete',
permission='delete',
request_method='POST'
)
@view_config(
context='ordr2:resources.OrderResource',
name='delete',
permission='delete',
request_method='POST'
)
def order_delete_form_processing(context, request):
if 'delete' in request.POST:
order_ids = [v for k, v in request.POST.items() if k == 'order']
orders = request.dbsession.\
query(Order).\
filter(Order.id.in_(order_ids)).\
all()
for order in orders:
request.dbsession.delete(order)
if len(orders) == 1:
request.flash('success', 'One order was deleted')
elif len(orders) > 1:
msg = '{} orders were deleted.'.format(len(orders))
request.flash('success', msg)
return HTTPFound(request.resource_url(request.root, 'orders'))
# single order processing
@view_config(
context='ordr2:resources.OrderResource',
name='delete',
permission='delete',
request_method='GET',
renderer='ordr2:templates/orders/delete.jinja2'
)
def order_delete_form(context, request):
return {'orders': [context.model]}