From b9e3be30ce18b5e448521ae3dd215dd2909c47fd Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Wed, 4 Oct 2017 17:51:00 +0200 Subject: [PATCH] added editing orders and placing custom orders splash screen for new orders still missing --- ordr2/models/orders.py | 26 +++ ordr2/schemas/orders.py | 39 ++-- ordr2/static/css/style.css | 10 +- ordr2/static/js/functions.js | 28 +-- ordr2/templates/deform/order_info_mapping.pt | 71 +++++++ ordr2/templates/orders/edit.jinja2 | 24 +++ .../orders/{order_list.jinja2 => list.jinja2} | 2 +- ordr2/templates/orders/new.jinja2 | 24 +++ ordr2/views/orders.py | 173 +++++++++++++++++- 9 files changed, 351 insertions(+), 46 deletions(-) create mode 100644 ordr2/templates/deform/order_info_mapping.pt create mode 100644 ordr2/templates/orders/edit.jinja2 rename ordr2/templates/orders/{order_list.jinja2 => list.jinja2} (99%) create mode 100644 ordr2/templates/orders/new.jinja2 diff --git a/ordr2/models/orders.py b/ordr2/models/orders.py index 4d67539..36d7dea 100644 --- a/ordr2/models/orders.py +++ b/ordr2/models/orders.py @@ -96,3 +96,29 @@ class Order(Base): def __str__(self): ''' string representation ''' return '{!s} ({!s})'.format(self.cas_description, self.vendor) + + + def _date_info(self, some_date, some_one): + if not some_date: + return '' + if some_one: + return '{!s} by {!s}'.format(some_date, some_one) + else: + return '{!s}'.format(some_date) + + + @property + def placed(self): + return self._date_info(self.created_date, self.created_by) + + @property + def approved(self): + return self._date_info(self.approval_date, self.approval_by) + + @property + def ordered(self): + return self._date_info(self.ordered_date, self.ordered_by) + + @property + def completed(self): + return self._date_info(self.completed_date, self.completed_by) diff --git a/ordr2/schemas/orders.py b/ordr2/schemas/orders.py index e2b0434..d56050c 100644 --- a/ordr2/schemas/orders.py +++ b/ordr2/schemas/orders.py @@ -66,33 +66,12 @@ class ConsumableSchema(CSRFSchema): 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): @@ -123,6 +102,9 @@ class OrderPricing(colander.Schema): quantity = colander.SchemaNode( colander.Integer(), validator=colander.Range(min=1), + widget=deform.widget.TextInputWidget( + css_class='number' + ), default=1 ) total_price = MoneyInputSchema( @@ -148,12 +130,15 @@ class NewOrderSchema(CSRFSchema): item_information = OrderItem() pricing = OrderPricing() - optional_informatoin = OrderOptionals() + optional_information = OrderOptionals() @classmethod def as_form(cls, request, **override): settings = { - 'buttons': ('Place Order', 'Cancel'), + 'buttons': ( + deform.Button(name='save', title='Place Order'), + deform.Button(name='cancel', title='Cancel') + ), 'css_class': 'form-horizontal' } settings.update(override) @@ -163,10 +148,14 @@ class NewOrderSchema(CSRFSchema): class EditOrderSchema(CSRFSchema): ''' edit or add an order ''' - order_information = OrderInformation() + order_information = OrderInformation( + widget=deform.widget.MappingWidget( + template='order_info_mapping.pt' + ) + ) item_information = OrderItem() pricing = OrderPricing() - optional_informatoin = OrderOptionals() + optional_information = OrderOptionals() @classmethod def as_form(cls, request, **override): diff --git a/ordr2/static/css/style.css b/ordr2/static/css/style.css index 1dab600..9dae3e9 100755 --- a/ordr2/static/css/style.css +++ b/ordr2/static/css/style.css @@ -725,15 +725,17 @@ input[value="password:mapping"] + div { margin-bottom:10px; } input[value="new_password:mapping"] + div { margin-bottom:10px; } .form-horizontal.user-settings fieldset > .controls { margin-left:0; } -.user-settings .panel-heading { +.user-settings .panel-heading, +.edit-order .panel-heading { font-size:150%; padding-top: 20px; padding-bottom: 20px; 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; } - - +td.column-pkg, td.column-price, td.column-total, td.column-amount { + text-align:right;} +input.number { text-align:right; } .moneyinput .amount { width:167px; text-align:right;} .moneyinput .currency { width:30px; text-align:center;} +.controls .form-control-static { padding-top:5px; } diff --git a/ordr2/static/js/functions.js b/ordr2/static/js/functions.js index ee43025..69cd03b 100755 --- a/ordr2/static/js/functions.js +++ b/ordr2/static/js/functions.js @@ -89,29 +89,29 @@ $(document).ready(function() { }); // calculator - if ( $('input[name="price_unit"]').length ) { - if( $('input[name="price_unit"]').val() != '' && $('input[name="quantity"]').val() != '' ){ - var total = $('input[name="price_unit"]').val().replace(",", ".") * $('input[name="quantity"]').val(); + if ( $('.item-unit_price input[name="amount"]').length ) { + if( $('.item-unit_price input[name="amount"]').val() != '' && $('input[name="quantity"]').val() != '' ){ + var total = $('.item-unit_price input[name="amount"]').val().replace(",", "") * $('input[name="quantity"]').val(); total = Math.round(total*100)/100; - $('input[name="price_total_disabled"]').attr( 'placeholder', total ); + $('.item-total_price input[name="amount"]').attr( 'value', total ); } - $('input[name="price_unit"], input[name="quantity"]').keyup(function() { - var total = $('input[name="price_unit"]').val().replace(",", ".") * $('input[name="quantity"]').val(); + $('.item-unit_price input[name="amount"], input[name="quantity"]').keyup(function() { + var total = $('.item-unit_price input[name="amount"]').val().replace(",", "") * $('input[name="quantity"]').val(); total = Math.round(total*100)/100; - $('input[name="price_total_disabled"]').attr( 'placeholder', total ); + $('.item-total_price input[name="amount"]').attr( 'value', total ); }); } - if ( $('input[name="currency"]').length ) { + if ( $('.item-unit_price input[name="currency"]').length ) { // added currency to total price - if( $('input[name="currency"]').val() != '' ){ - $('input[name="currency_disabled"]').attr( 'placeholder', $('input[name="currency"]').val() ); + if( $('.item-unit_price input[name="currency"]').val() != '' ){ + $('.item-total_price input[name="currency"]').attr( 'value', $('.item-unit_price input[name="currency"]').val() ); } - $('input[name="currency"]').keyup(function() { - $('input[name="currency_disabled"]').attr( 'placeholder', $('input[name="currency"]').val() ); + $('.item-unit_price input[name="currency"]').keyup(function() { + $('.item-total_price input[name="currency"]').attr( 'value', $('.item-unit_price input[name="currency"]').val() ); }); - $('input[name="currency"]').change(function() { - $('input[name="currency_disabled"]').attr( 'placeholder', $('input[name="currency"]').val() ); + $('.item-unit_price input[name="currency"]').change(function() { + $('.item-total_price input[name="currency"]').attr( 'value', $('.item-unit_price input[name="currency"]').val() ); }); } diff --git a/ordr2/templates/deform/order_info_mapping.pt b/ordr2/templates/deform/order_info_mapping.pt new file mode 100644 index 0000000..0a72e9d --- /dev/null +++ b/ordr2/templates/deform/order_info_mapping.pt @@ -0,0 +1,71 @@ + + +
+
${title}
+
+ +
+

+ There was a problem with this section +

+

${errormsg}

+
+ +
+ ${description} +
+ + ${field.start_mapping()} + +
+
+ +
+ +
+

+ ${request.context.model.placed} +

+
+
+ +
+ +
+

+ ${request.context.model.approved} +

+
+
+ +
+ +
+

+ ${request.context.model.ordered} +

+
+
+ +
+ +
+

+ ${request.context.model.completed} +

+
+
+ + ${field.end_mapping()} + +
+
+ +
diff --git a/ordr2/templates/orders/edit.jinja2 b/ordr2/templates/orders/edit.jinja2 new file mode 100644 index 0000000..b049c02 --- /dev/null +++ b/ordr2/templates/orders/edit.jinja2 @@ -0,0 +1,24 @@ +{% extends "ordr2:templates/layout.jinja2" %} +{% import 'ordr2:templates/macros.jinja2' as macros with context %} + +{% block subtitle %} Order | {{ context.model.cas_description }} {% endblock subtitle %} + +{% block content %} +
+ +
+
+
+

Edit Order: {{ context.model.cas_description }}

+
+
+
+
+ {{ macros.flash_messages() }} + {{form.render()|safe}} +
+
+
+ +
+{% endblock content %} diff --git a/ordr2/templates/orders/order_list.jinja2 b/ordr2/templates/orders/list.jinja2 similarity index 99% rename from ordr2/templates/orders/order_list.jinja2 rename to ordr2/templates/orders/list.jinja2 index 0159ce7..7e907ee 100644 --- a/ordr2/templates/orders/order_list.jinja2 +++ b/ordr2/templates/orders/list.jinja2 @@ -19,7 +19,7 @@
-
+