Browse Source

status change on multiple orders

php2python
Holger Frey 7 years ago
parent
commit
e8305b97a3
  1. 3
      ordr2/events.py
  2. 36
      ordr2/templates/emails/order.jinja2
  3. 75
      ordr2/templates/orders/edit_multiple_stati.jinja2
  4. 98
      ordr2/views/orders.py

3
ordr2/events.py

@ -30,6 +30,9 @@ class PasswordReset(UserNotification):
subject='[ordr] Password Reset' subject='[ordr] Password Reset'
template = 'ordr2:templates/emails/password_reset.jinja2' template = 'ordr2:templates/emails/password_reset.jinja2'
class OrderStatusChange(UserNotification):
subject='[ordr] Order Status Change'
template = 'ordr2:templates/emails/order.jinja2'
@subscriber(UserLogIn) @subscriber(UserLogIn)

36
ordr2/templates/emails/order.jinja2

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ordr Notification</title>
<link href='http://fonts.googleapis.com/css?family=Anton&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{{request.static_url('ordr2:static/css/email.css')}}" type="text/css" media="screen">
</head>
<body>
<h1>Hi there!</h1>
<p>
Your purchase of the following item
{% if data.status.name == 'ORDERED' %}
has <u>been orderd</u>:
{% else %}
has <u>arrived</u>:
{% endif %}
<strong>{{ data }}</strong>
</p>
<p>
If you want to check details about the purchase go here: <a href="{{ request.resource_url(request.root, 'orders', data.id) }}">{{ request.resource_url(request.root, 'orders', data.id) }}</a>
</p>
<p>
</p>
<p class="signature">
Regards,
<br/>
<span class="brand">ordr</span>
</p>
<p class="footprint">
<small>Please don't respont to this email! This is an automatically generated notification by the system.</small>
<a href="http://distractedbysquirrels.com/" target="_blank" title="This software was originally written by Sebastian Sebald." class="icon-dbs"></a>
</p>
</body>
</html>

75
ordr2/templates/orders/edit_multiple_stati.jinja2

@ -0,0 +1,75 @@
{% extends "ordr2:templates/layout.jinja2" %}
{% import 'ordr2:templates/macros.jinja2' as macros with context %}
{% block subtitle %} Oders | Change Status {% endblock subtitle %}
{% block content %}
<div class="content controls">
<div class="container-fluid">
<div class="row-fluid">
<div class="page-controls">
<h1>Change Status of Order{{ 's' if orders|length > 1 }}</h1>
</div>
</div>
<div class="row">
<div class="span10">
<div class="action-header">
<h3>The status of the following order{{ 's' if orders|length > 1 }} will be changed:</h3>
</div>
<form action="{{ request.resource_url(context, 'stati') }}" 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>Placed by</th>
<th>Status</th>
</thead>
<tbody>
{% for order in orders %}
<tr>
<td>{{ order.created_date }}</td>
<td>{{ order.cas_description }} </td>
<td>{{ order.created_by }} </td>
<td>
<select name="order-{{ order.id }}" class="select-status span2">
{% for value, display in stati %}
<option value="{{ value }}" {{ 'selected="selected"' if value == order.status.name }}>{{ display }}</option>
{% endfor %}
</select>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<fieldset class="form-actions">
<div class="right">
<button name="change" type="submit" value="change" class="btn btn-large btn-danger">Change {{ 'Status' if orders|length > 1 else 'Stati'}}</button>
<button name="cancel" type="submit" value="cancel" class="btn btn-large">Cancel</button>
</div>
<div class="btn-group quick-action left" data-action="order">
<a data-value="APPROVAL" href="#" class="btn btn-large btn-primary">Set all to Approval</a>
<a href="#" data-toggle="dropdown" class="btn btn-large btn-primary dropdown-toggle"><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a data-value="ORDERED" href="#">Set all to Ordered</a></li>
<li><a data-value="COMPLETED" href="#">Set all to Completed</a></li>
</ul>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
{% endblock content %}

98
ordr2/views/orders.py

@ -4,12 +4,31 @@ from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render from pyramid.renderers import render
from pyramid.view import view_config from pyramid.view import view_config
from ordr2.events import AccountActivation, PasswordReset from ordr2.events import OrderStatusChange
from ordr2.models import Category, Order, OrderStatus from ordr2.models import Category, Order, OrderStatus, User
from ordr2.schemas.orders import ConsumableSchema from ordr2.schemas.orders import ConsumableSchema
from . import update_column_display from . import update_column_display
# helper method
def change_in_order_status(request, order, old):
noteworthy = False
if old != OrderStatus.ORDERED and order.status == OrderStatus.ORDERED:
noteworthy = True
if old != OrderStatus.COMPLETED and order.status == OrderStatus.COMPLETED:
noteworthy = True
if noteworthy:
account = request.dbsession.\
query(User).\
filter_by(user_name=order.created_by).\
first()
if account:
event = OrderStatusChange(request, account, order)
request.registry.notify(event)
# oder list and multiple editing # oder list and multiple editing
@view_config( @view_config(
@ -34,4 +53,79 @@ def change_column_view(context, request):
''' changes the columns to display ''' ''' changes the columns to display '''
update_column_display(request, 'orders') update_column_display(request, 'orders')
return HTTPFound(context.url()) return HTTPFound(context.url())
@view_config(
context='ordr2:resources.OrderList',
name='actions',
request_param='action=status',
permission='edit',
request_method='POST',
renderer='ordr2:templates/orders/edit_multiple_stati.jinja2'
)
def edit_multiple_stati_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())
stati = [(s.name, s.value.capitalize()) for s in OrderStatus]
return {'orders': orders, 'stati': stati}
@view_config(
context='ordr2:resources.OrderList',
name='stati',
permission='edit',
request_method='POST'
)
def edit_multiple_stati_form_processing(context, request):
if 'change' in request.POST:
count = 0
for key, value in request.POST.items():
if not key.startswith('order-'):
continue
_, order_id = key.split('-', 1)
order = request.dbsession.query(Order).get(order_id)
if order:
old_status = order.status
try:
order.status = OrderStatus[value]
except ValueError:
pass
if old_status != order.status:
change_in_order_status(request, order, old_status)
count += 1
if count == 1:
request.flash('success', 'One order was updated')
elif count > 1:
msg = '{} orders were updated.'.format(count)
request.flash('success', msg)
return HTTPFound(context.url())