From 76e0d4e0340557200e0850d3cebbeffa87f2eb70 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Wed, 4 Oct 2017 14:36:44 +0200 Subject: [PATCH] added order schemas --- ordr2/schemas/orders.py | 123 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/ordr2/schemas/orders.py b/ordr2/schemas/orders.py index 575d3ca..e2b0434 100644 --- a/ordr2/schemas/orders.py +++ b/ordr2/schemas/orders.py @@ -1,11 +1,12 @@ import colander import deform -from ordr2.models import Category +from ordr2.models import Category, OrderStatus from . import CSRFSchema, MoneyInputSchema CATEGORIES = [(c.name, c.value.capitalize()) for c in Category] +STATI = [(s.name, s.value.capitalize()) for s in OrderStatus] # schema for user registration @@ -63,3 +64,123 @@ class ConsumableSchema(CSRFSchema): } settings.update(override) return super().as_form(request, **settings) + + + +class OrderInformation(colander.Schema): + + status = colander.SchemaNode( + colander.String(), + widget=deform.widget.SelectWidget(values=STATI) + ) + placed = colander.SchemaNode( + colander.String(), + widget=deform.widget.TextInputWidget(readonly=True), + missing='' + ) + approval = colander.SchemaNode( + colander.String(), + widget=deform.widget.TextInputWidget(readonly=True), + missing='' + ) + ordered = colander.SchemaNode( + colander.String(), + widget=deform.widget.TextInputWidget(readonly=True), + missing='' + ) + completed = colander.SchemaNode( + colander.String(), + widget=deform.widget.TextInputWidget(readonly=True), + missing='' + ) + + +class OrderItem(colander.Schema): + + 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() + ) + + +class OrderPricing(colander.Schema): + + unit_price = MoneyInputSchema( + readonly=False + ) + quantity = colander.SchemaNode( + colander.Integer(), + validator=colander.Range(min=1), + default=1 + ) + total_price = MoneyInputSchema( + readonly=True + ) + + +class OrderOptionals(colander.Schema): + + account = colander.SchemaNode( + colander.String(), + missing='' + ) + comment = colander.SchemaNode( + colander.String(), + widget=deform.widget.TextAreaWidget(rows=5), + missing='' + ) + + +class NewOrderSchema(CSRFSchema): + ''' edit or add an order ''' + + item_information = OrderItem() + pricing = OrderPricing() + optional_informatoin = OrderOptionals() + + @classmethod + def as_form(cls, request, **override): + settings = { + 'buttons': ('Place Order', 'Cancel'), + 'css_class': 'form-horizontal' + } + settings.update(override) + return super().as_form(request, **settings) + + +class EditOrderSchema(CSRFSchema): + ''' edit or add an order ''' + + order_information = OrderInformation() + item_information = OrderItem() + pricing = OrderPricing() + optional_informatoin = OrderOptionals() + + @classmethod + def as_form(cls, request, **override): + settings = { + 'buttons': ( + deform.Button(name='save', title='Edit Order'), + deform.Button( + name='delete', + title='Delete Order', + css_class='btn-danger' + ), + deform.Button(name='cancel', title='Cancel') + ), + 'css_class': 'form-horizontal' + } + settings.update(override) + return super().as_form(request, **settings)