diff --git a/ordr2/schemas/__init__.py b/ordr2/schemas/__init__.py
index e249e79..af78273 100644
--- a/ordr2/schemas/__init__.py
+++ b/ordr2/schemas/__init__.py
@@ -32,3 +32,35 @@ class CSRFSchema(colander.Schema):
form = deform.Form(schema, action=url, **kwargs)
return form
+
+
+class MoneyInputSchema(colander.Schema):
+
+ amount = colander.SchemaNode(
+ colander.Decimal(),
+ widget=deform.widget.MoneyInputWidget(
+ readonly_template='textinput_disabled.pt',
+ css_class='moneyinput amount'
+ ),
+ )
+ currency = colander.SchemaNode(
+ colander.String(),
+ default='EUR',
+ widget=deform.widget.TextInputWidget(
+ readonly_template='textinput_disabled.pt',
+ css_class='moneyinput currency'
+ )
+ )
+
+ def __init__(self, *args, **kwargs):
+ if 'widget' not in kwargs:
+ readonly = kwargs.pop('readonly', False)
+ kwargs['widget'] = deform.widget.MappingWidget(
+ category='default',
+ template='money_mapping.pt',
+ readonly_template='money_mapping_disabled.pt',
+ item_template='money_mapping_item.pt',
+ item_readonly_template='money_mapping_item_diabled.pt',
+ readonly=readonly,
+ )
+ super().__init__(*args, **kwargs)
diff --git a/ordr2/schemas/orders.py b/ordr2/schemas/orders.py
index c34eba4..575d3ca 100644
--- a/ordr2/schemas/orders.py
+++ b/ordr2/schemas/orders.py
@@ -3,7 +3,7 @@ import deform
from ordr2.models import Category
-from . import CSRFSchema
+from . import CSRFSchema, MoneyInputSchema
CATEGORIES = [(c.name, c.value.capitalize()) for c in Category]
@@ -28,13 +28,8 @@ class ConsumableSchema(CSRFSchema):
package_size = colander.SchemaNode(
colander.String()
)
- unit_price = colander.SchemaNode(
- colander.Decimal(),
- widget=deform.widget.MoneyInputWidget()
- )
- currency = colander.SchemaNode(
- colander.String(),
- default='EUR'
+ unit_price = MoneyInputSchema(
+ readonly=False
)
comment = colander.SchemaNode(
colander.String(),
diff --git a/ordr2/static/css/style.css b/ordr2/static/css/style.css
index 95779bf..1dab600 100755
--- a/ordr2/static/css/style.css
+++ b/ordr2/static/css/style.css
@@ -733,3 +733,7 @@ input[value="new_password:mapping"] + div { margin-bottom:10px; }
border-bottom: 1px solid #aaa;}
div.alert a { color:inherit; text-decoration:underline; }
td.column-pkg, td.column-price { text-align:right; }
+
+
+.moneyinput .amount { width:167px; text-align:right;}
+.moneyinput .currency { width:30px; text-align:center;}
diff --git a/ordr2/templates/deform/money_mapping.pt b/ordr2/templates/deform/money_mapping.pt
new file mode 100644
index 0000000..de2a8cf
--- /dev/null
+++ b/ordr2/templates/deform/money_mapping.pt
@@ -0,0 +1,36 @@
+
+
+ ${field.start_mapping()}
+
+
+ ${field.end_mapping()}
+
+
+ ${msg}
+
+
+
+ ${field.description}
+
+
+
+
diff --git a/ordr2/templates/deform/money_mapping_disabled.pt b/ordr2/templates/deform/money_mapping_disabled.pt
new file mode 100644
index 0000000..e25dfef
--- /dev/null
+++ b/ordr2/templates/deform/money_mapping_disabled.pt
@@ -0,0 +1,36 @@
+
+
+ ${field.start_mapping()}
+
+
+ ${field.end_mapping()}
+
+
+ ${msg}
+
+
+
+ ${field.description}
+
+
+
+
diff --git a/ordr2/templates/deform/money_mapping_item.pt b/ordr2/templates/deform/money_mapping_item.pt
new file mode 100644
index 0000000..26ef52d
--- /dev/null
+++ b/ordr2/templates/deform/money_mapping_item.pt
@@ -0,0 +1,25 @@
+
+
+
+ ${input_prepend}${input_append}
+
+
diff --git a/ordr2/templates/deform/money_mapping_item_diabled.pt b/ordr2/templates/deform/money_mapping_item_diabled.pt
new file mode 100644
index 0000000..1046952
--- /dev/null
+++ b/ordr2/templates/deform/money_mapping_item_diabled.pt
@@ -0,0 +1,25 @@
+
+
+
+ ${input_prepend}${input_append}
+
+
diff --git a/ordr2/templates/deform/textinput_disabled.pt b/ordr2/templates/deform/textinput_disabled.pt
index d260d0b..0fa6da0 100644
--- a/ordr2/templates/deform/textinput_disabled.pt
+++ b/ordr2/templates/deform/textinput_disabled.pt
@@ -1,8 +1,8 @@
diff --git a/ordr2/views/admin.py b/ordr2/views/admin.py
index 08cd64f..f162ac7 100644
--- a/ordr2/views/admin.py
+++ b/ordr2/views/admin.py
@@ -309,8 +309,8 @@ def consumable_new_form_processing(context, request):
vendor=appstruct['vendor'],
catalog_nr=appstruct['catalog_nr'],
package_size=appstruct['package_size'],
- unit_price=appstruct['unit_price'],
- currency=appstruct['currency'],
+ unit_price=appstruct['unit_price']['amount'],
+ currency=appstruct['unit_price']['currency'],
comment=appstruct['comment']
)
request.dbsession.add(consumable)
@@ -336,8 +336,10 @@ def consumable_edit_form(context, request):
'vendor': context.model.vendor,
'catalog_nr': context.model.catalog_nr,
'package_size': context.model.package_size,
- 'unit_price': context.model.unit_price,
- 'currency': context.model.currency,
+ 'unit_price': {
+ 'amount': context.model.unit_price,
+ 'currency': context.model.currency
+ },
'comment': context.model.comment
}
form.set_appstruct(form_data)
@@ -367,8 +369,8 @@ def consumable_edit_form_processing(context, request):
context.model.vendor = appstruct['vendor']
context.model.catalog_nr = appstruct['catalog_nr']
context.model.package_size = appstruct['package_size']
- context.model.unit_price = appstruct['unit_price']
- context.model.currency = appstruct['currency']
+ context.model.unit_price = appstruct['unit_price']['amount']
+ context.model.currency = appstruct['unit_price']['currency']
context.model.comment = appstruct['comment']
msg = 'Consumable {!s} updated.'.format(context.model)