diff --git a/ordr2/events.py b/ordr2/events.py index 3218f93..6b264cd 100644 --- a/ordr2/events.py +++ b/ordr2/events.py @@ -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): 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) diff --git a/ordr2/resources/__init__.py b/ordr2/resources/__init__.py index d6bb8ac..601a6f5 100644 --- a/ordr2/resources/__init__.py +++ b/ordr2/resources/__init__.py @@ -20,7 +20,8 @@ class Root(BaseResource): nodes = { 'account': Account, - 'admin': Admin + 'admin': Admin, + 'orders': OrderList } def __init__(self, request): diff --git a/ordr2/resources/orders.py b/ordr2/resources/orders.py index 078cc2a..e3c0af6 100644 --- a/ordr2/resources/orders.py +++ b/ordr2/resources/orders.py @@ -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): 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): 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): '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) diff --git a/ordr2/templates/orders/order_list.jinja2 b/ordr2/templates/orders/order_list.jinja2 new file mode 100644 index 0000000..4c56b81 --- /dev/null +++ b/ordr2/templates/orders/order_list.jinja2 @@ -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 %} +