diff --git a/ordr2/resources/__init__.py b/ordr2/resources/__init__.py index 8a3fd06..d3c0e75 100644 --- a/ordr2/resources/__init__.py +++ b/ordr2/resources/__init__.py @@ -1,7 +1,13 @@ from pyramid.security import Allow, Everyone from .account import Account, PasswordResetAccount -from .admin import Admin, UserList, UserAccount +from .admin import ( + Admin, + ConsumableList, + ConsumableResource, + UserList, + UserAccount + ) from .base import BaseResource diff --git a/ordr2/resources/admin.py b/ordr2/resources/admin.py index af2feb2..1497180 100644 --- a/ordr2/resources/admin.py +++ b/ordr2/resources/admin.py @@ -87,6 +87,7 @@ class ConsumableList(BaseResource, PaginationResourceMixin): def __acl__(self): return [ (Allow, 'role:admin', 'view'), + (Allow, 'role:admin', 'create'), (Allow, 'role:admin', 'edit'), (Allow, 'role:admin', 'delete'), DENY_ALL @@ -98,7 +99,7 @@ class ConsumableList(BaseResource, PaginationResourceMixin): query = dbsession.query(self.sql_model_class) category_name = filter_params.get('category', None) try: - category_name = cat_name.lower() + category_name = category_name.lower() category = Category(category_name) query = query.filter_by(category=category) except (AttributeError, ValueError): @@ -132,7 +133,8 @@ class ConsumableList(BaseResource, PaginationResourceMixin): class Admin(BaseResource): nodes = { - 'users': UserList + 'users': UserList, + 'consumables': ConsumableList, } def __acl__(self): diff --git a/ordr2/schemas/orders.py b/ordr2/schemas/orders.py new file mode 100644 index 0000000..c34eba4 --- /dev/null +++ b/ordr2/schemas/orders.py @@ -0,0 +1,70 @@ +import colander +import deform + +from ordr2.models import Category + +from . import CSRFSchema + +CATEGORIES = [(c.name, c.value.capitalize()) for c in Category] + +# schema for user registration + +class ConsumableSchema(CSRFSchema): + ''' edit or add consumable ''' + + cas_description = colander.SchemaNode( + colander.String() + ) + category = colander.SchemaNode( + colander.String(), + widget=deform.widget.SelectWidget(values=CATEGORIES) + ) + catalog_nr = colander.SchemaNode( + colander.String() + ) + vendor = colander.SchemaNode( + colander.String() + ) + package_size = colander.SchemaNode( + colander.String() + ) + unit_price = colander.SchemaNode( + colander.Decimal(), + widget=deform.widget.MoneyInputWidget() + ) + currency = colander.SchemaNode( + colander.String(), + default='EUR' + ) + comment = colander.SchemaNode( + colander.String(), + widget=deform.widget.TextAreaWidget(rows=5), + missing='' + ) + + @classmethod + def as_form(cls, request, **override): + is_new_consumable = override.pop('is_new_consumable', False) + if is_new_consumable: + settings = { + 'buttons': ( + deform.Button(name='save', title='Add Consumable'), + deform.Button(name='cancel', title='Cancel') + ), + 'css_class': 'form-horizontal', + } + else: + settings = { + 'buttons': ( + deform.Button(name='save', title='Save changes'), + deform.Button( + name='delete', + title='Delete Consumable', + css_class='btn-danger' + ), + deform.Button(name='cancel', title='Cancel') + ), + 'css_class': 'form-horizontal', + } + settings.update(override) + return super().as_form(request, **settings) diff --git a/ordr2/static/css/style.css b/ordr2/static/css/style.css index 909455c..95779bf 100755 --- a/ordr2/static/css/style.css +++ b/ordr2/static/css/style.css @@ -732,3 +732,4 @@ input[value="new_password:mapping"] + div { margin-bottom:10px; } margin-bottom: 20px; border-bottom: 1px solid #aaa;} div.alert a { color:inherit; text-decoration:underline; } +td.column-pkg, td.column-price { text-align:right; } diff --git a/ordr2/templates/admin/consumable_delete.jinja2 b/ordr2/templates/admin/consumable_delete.jinja2 new file mode 100755 index 0000000..98745a1 --- /dev/null +++ b/ordr2/templates/admin/consumable_delete.jinja2 @@ -0,0 +1,70 @@ +{% extends "ordr2:templates/layout.jinja2" %} +{% import 'ordr2:templates/macros.jinja2' as macros with context %} + +{% block subtitle %} Admin | Consumable | Confirm Delete {% endblock subtitle %} + +{% block content %} +
Actions | + + + + {% for consumable in consumables %} +|||||||
---|---|---|---|---|---|---|---|
{{ consumable.model.cas_description }} | +{{ consumable.model.category.name|capitalize }} | +{{ consumable.model.catalog_nr }} | +{{ consumable.model.vendor }} | +{{ consumable.model.package_size }} | +{{ '%.2f'|format(consumable.model.unit_price) }} | +{{ consumable.model.currency }} | ++ edit + delete + | +
Your query didn't return any data.
+