Browse Source

added viewing order list

php2python
Holger Frey 7 years ago
parent
commit
26f7ea962c
  1. 19
      ordr2/events.py
  2. 3
      ordr2/resources/__init__.py
  3. 14
      ordr2/resources/orders.py
  4. 190
      ordr2/templates/orders/order_list.jinja2
  5. 20
      ordr2/views/__init__.py
  6. 37
      ordr2/views/orders.py

19
ordr2/events.py

@ -2,6 +2,9 @@ from pyramid.events import NewRequest, subscriber @@ -2,6 +2,9 @@ from pyramid.events import NewRequest, subscriber
from pyramid.renderers import render
from pyramid_mailer.message import Message
from ordr2.views import set_display_defaults
class UserLogIn(object):
def __init__(self, request, user):
self.request = request
@ -28,18 +31,16 @@ class PasswordReset(UserNotification): @@ -28,18 +31,16 @@ class PasswordReset(UserNotification):
template = 'ordr2:templates/emails/password_reset.jinja2'
@subscriber(UserLogIn)
def set_display_defaults_on_log_in(event):
set_display_defaults(event.request)
@subscriber(NewRequest)
def set_display_defaults(event):
def check_display_defaults(event):
if event.request.user and 'display' not in event.request.session:
defaults = {
'users': {
'first': True,
'last': True,
'email': True,
}
}
event.request.session['display'] = defaults
set_display_defaults(event.request)
@subscriber(UserNotification)

3
ordr2/resources/__init__.py

@ -20,7 +20,8 @@ class Root(BaseResource): @@ -20,7 +20,8 @@ class Root(BaseResource):
nodes = {
'account': Account,
'admin': Admin
'admin': Admin,
'orders': OrderList
}
def __init__(self, request):

14
ordr2/resources/orders.py

@ -14,8 +14,8 @@ class OrderResource(BaseResource): @@ -14,8 +14,8 @@ class OrderResource(BaseResource):
(Allow, 'role:purchaser', 'delete'),
]
if self.model.status == OrderStatus.OPEN:
acl.append( (Allow, 'user:' + str(self.model.username), 'edit') )
acl.append( (Allow, 'user:' + str(self.model.username), 'delete') )
acl.append( (Allow, 'user:' + str(self.model.created_by), 'edit') )
acl.append( (Allow, 'user:' + str(self.model.created_by), 'delete') )
acl.append(DENY_ALL)
return acl
@ -23,7 +23,7 @@ class OrderResource(BaseResource): @@ -23,7 +23,7 @@ class OrderResource(BaseResource):
class OrderList(BaseResource, PaginationResourceMixin):
sql_model_class = Order
child_resource_class = OrderResource
default_sorting = 'created.asc'
default_sorting = 'created.desc'
default_items_per_page = 12
def __acl__(self):
@ -47,7 +47,7 @@ class OrderList(BaseResource, PaginationResourceMixin): @@ -47,7 +47,7 @@ class OrderList(BaseResource, PaginationResourceMixin):
query = query.filter_by(status=status)
except (AttributeError, ValueError):
status_name = None
self.filters['category'] = status_name
self.filters['status'] = status_name
user_name = filter_params.get('user', None)
if user_name:
@ -64,12 +64,12 @@ class OrderList(BaseResource, PaginationResourceMixin): @@ -64,12 +64,12 @@ class OrderList(BaseResource, PaginationResourceMixin):
'category': 'category',
'catalog': 'catalog_nr',
'vendor': 'vendor',
'pkg': 'package_size',
'price': 'unit_price',
'currency': 'currency',
'amount': 'amount',
'total': 'total_price',
'created': 'created_date'
'created': 'created_date',
'user': 'created_by',
'status': 'status',
}
name = available_fields.get(sorting.field, None)
model_field = getattr(self.sql_model_class, name, None)

190
ordr2/templates/orders/order_list.jinja2

@ -0,0 +1,190 @@ @@ -0,0 +1,190 @@
{% extends "ordr2:templates/layout.jinja2" %}
{% import 'ordr2:templates/macros.jinja2' as macros with context %}
{% block subtitle %} Orders {% endblock subtitle %}
{% block content %}
<div class="content controls">
<div class="container-fluid controls">
<div class="row-fluid">
<div class="span2">
<div class="page-controls">
<h1>
Users
</h1>
</div>
{{ macros.filter_box('All Orders', 'status', stati, {'user': None} ) }}
{{ macros.filter_box('My Orders', 'status', stati, {'user': request.user.user_name} ) }}
</div>
<div class="span10">
<form action="{{ request.resource_url(context, 'actions') }}" method="POST">
<input type="hidden" name="csrf_token" value="{{get_csrf_token()}}">
<div class="page-controls">
<div class="input-append search">
<input type="search" name="search" size="30" placeholder="Search">
<label class="add-on">
<button type="submit" class="search" name="action" value="search">Search</button>
</label>
</div>
<div class="actions">
{% if request.has_permission('create', context) %}
<a href="{{ request.resource_url(context, 'splash') }}" rel="tooltip" data-original-title="New" class="btn-flat single"><i class="add"></i></a>
{% endif %}
{% if request.has_permission('edit', context) or request.has_permission('delete', context) %}
<div class="btn-group marking-needed">
{% if request.has_permission('edit', context) %}
<button rel="tooltip" data-original-title="Change Status" value="status" type="submit" name="action" class="btn-flat"><i class="clip"></i></button>
{% endif %}
{% if request.has_permission('delete', context) %}
<button rel="tooltip" data-original-title="Delete" value="delete" type="submit" name="action" class="btn-flat"><i class="trash"></i></button>
{% endif %}
</div>
{% endif %}
<a href="#modal-display" rel="tooltip" data-original-title="Display Options" class="btn-flat single" data-toggle="modal"><i class="eye"></i></a>
<button rel="tooltip" data-original-title="Download View" value="export" type="submit" name="action" class="btn-flat"><i class="download"></i></button>
</div>
</div>
{{ macros.flash_messages() }}
{% if orders %}
{{ macros.show_or_hide_columns('orders') }}
<table class="table">
<thead>
<th class="center">
<input type="checkbox" value="all" name="mark_all" id="mark_all">
</th>
{{ macros.sortable_table_header('Date Created', 'created') }}
{{ macros.sortable_table_header('CAS / Description', 'cas') }}
{{ macros.sortable_table_header('Vendor', 'vendor') }}
{{ macros.sortable_table_header('Catalog Nr.', 'catalog') }}
{{ macros.sortable_table_header('Unit Price', 'price') }}
{{ macros.sortable_table_header('Quantity', 'amount') }}
{{ macros.sortable_table_header('Total Price', 'total') }}
{{ macros.sortable_table_header('Account', 'account') }}
{{ macros.sortable_table_header('Category', 'category') }}
{{ macros.sortable_table_header('Status', 'status') }}
{{ macros.sortable_table_header('Ordered By', 'user') }}
<th>Actions</th>
</thead>
<tbody>
{% for order in orders %}
<tr>
<td class="center">
<input type="checkbox" name="marked" value="{{ order.model.id }}">
</td>
<td class="column-created">{{ order.model.created_date }}</td>
<td class="column-cas">{{ order.model.cas_description }}</td>
<td class="column-vendor">{{ order.model.vendor }}</td>
<td class="column-catalog">{{ order.model.catalog_nr }}</td>
<td class="column-price">{{ '%.2f'|format(order.model.unit_price) }} {{ order.model.currency }}</td>
<td class="column-amount">{{ order.model.amount }}</td>
<td class="column-total">{{ '%.2f'|format(order.model.total_price) }} {{ order.model.currency }}</td>
<td class="column-account">{{ order.model.account }}</td>
<td class="column-category">{{ order.model.category.value|capitalize }}</td>
<td class="column-status">{{ order.model.status.value|capitalize }}</td>
<td class="column-user">
<a href="{{ request.resource_url(context, query={'user': order.model.created_by}) }}" title="click to view all orders from user">{{ order.model.created_by }}</a>
</td>
<td>
{% if request.has_permission('edit', order) %}
<a href="{{ request.resource_url(order, 'edit') }}" class="action edit" title="Edit Order">edit</a>
{% else %}
<a href="{{ request.resource_url(order) }}" class="action edit" title="Edit Order">edit</a>
{% endif %}
{% if request.has_permission('delete', order) %}
<a href="{{ request.resource_url(order, 'delete') }}" class="action delete" title="Delete Order">delete</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{{ macros.pagination() }}
{% else %}
<div class="alert alert-block alert-error">
<h4 class="alert-heading">Oh snap! Nothing to display!</h4>
<p>Your query didn't return any data.</p>
</div>
{% endif %}
</form>
</div>
</div>
</div>
<div id="modal-display" class="modal hide fade">
<form action="{{ request.resource_url(context, 'changeview', query=context.query_params()) }}" method="POST" class="checkslist">
<input type="hidden" name="csrf_token" value="{{get_csrf_token()}}">
{% set display = request.session.get('display', dict()) %}
{% set settings = display.get('orders', dict()) %}
<div class="modal-header">
<a href="#" class="close" data-dismiss="modal">×</a>
<h3>Display Options</h3>
</div>
<div class="modal-body">
<p class="help-block"><span class="label notice">Notice</span> If the displayed information is too cluttered, deselect some fields below. This will temporaly remove them from your view and should help you stay on top of things.</p>
<div class="checklist">
<fieldset class="left">
<label class="checkbox">
<input type="checkbox" value="created" name="display" checked="checked" disabled="disabled">
Date Created
</label>
<label class="checkbox">
<input type="checkbox" value="cas" name="display" {{ 'checked="checked"' if settings.get('cas') }}>
CAS / Description
</label>
<label class="checkbox">
<input type="checkbox" value="vendor" name="display" {{ 'checked="checked"' if settings.get('vendor') }}>
Vendor
</label>
<label class="checkbox">
<input type="checkbox" value="catalog" name="display" {{ 'checked="checked"' if settings.get('catalog') }}>
Catalog Number
</label>
<label class="checkbox">
<input type="checkbox" value="price" name="display" {{ 'checked="checked"' if settings.get('price') }}>
Unit Price
</label>
<label class="checkbox">
<input type="checkbox" value="amount" name="display" {{ 'checked="checked"' if settings.get('amount') }}>
Quantity
</label>
</fieldset>
<fieldset class="right">
<label class="checkbox">
<input type="checkbox" value="total" name="display" {{ 'checked="checked"' if settings.get('total') }}>
Total Price
</label>
<label class="checkbox">
<input type="checkbox" value="account" name="display" {{ 'checked="checked"' if settings.get('account') }}>
Account
</label>
<label class="checkbox">
<input type="checkbox" value="category" name="display" checked="checked" disabled="disabled">
Category
</label>
<label class="checkbox">
<input type="checkbox" value="status" name="display" checked="checked" disabled="disabled">
Work Status
</label>
<label class="checkbox">
<input type="checkbox" value="user" name="display" checked="checked" disabled="disabled">
Ordered by
</label>
</fieldset>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="submit">Apply Changes</button>
<a data-dismiss="modal" class="btn" href="#">Close</a>
</div>
</form>
</div>
</div>
{% endblock content %}

20
ordr2/views/__init__.py

@ -22,6 +22,26 @@ def update_column_display(request, section): @@ -22,6 +22,26 @@ def update_column_display(request, section):
request.session['display'][section] = display
def set_display_defaults(request):
defaults = {
'users': {
'first': True,
'last': True,
'email': True,
},
'orders': {
'account': False,
'cas': True,
'catalog': False,
'vendor': True,
'price': False,
'amount': False,
'total': True,
}
}
request.session['display'] = defaults
def includeme(config):
''' adding request helpers and static views '''
config.add_request_method(flash, 'flash')

37
ordr2/views/orders.py

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
import deform
from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render
from pyramid.view import view_config
from ordr2.events import AccountActivation, PasswordReset
from ordr2.models import Category, Order, OrderStatus
from ordr2.schemas.orders import ConsumableSchema
from . import update_column_display
# oder list and multiple editing
@view_config(
context='ordr2:resources.OrderList',
permission='view',
renderer='ordr2:templates/orders/order_list.jinja2'
)
def order_list(context, request):
''' display the order list '''
orders = context.items()
stati = [(s.value.lower(), s.value.capitalize()) for s in OrderStatus]
return {'orders':orders, 'stati':stati}
@view_config(
context='ordr2:resources.OrderList',
name = 'changeview',
permission='view',
request_method='POST'
)
def change_column_view(context, request):
''' changes the columns to display '''
update_column_display(request, 'orders')
return HTTPFound(context.url())