summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2019-09-20 12:33:29 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2019-09-20 12:49:12 +0200
commit5bd4b53d619ea14cd01a2e5adbfd1f2b8992ab9c (patch)
tree8c8b7d7b6be66af04a1aca864529680481278eef
parent23609eb945514140f8601107ef04ae9d1dcfdb86 (diff)
new field type: decimal
-rw-r--r--docs/field_types.rst2
-rw-r--r--lesana/collection.py16
2 files changed, 18 insertions, 0 deletions
diff --git a/docs/field_types.rst b/docs/field_types.rst
index 89065aa..baf2c5e 100644
--- a/docs/field_types.rst
+++ b/docs/field_types.rst
@@ -10,6 +10,8 @@ integer:
.
float:
.
+decimal:
+ .
timestamp:
.
boolean:
diff --git a/lesana/collection.py b/lesana/collection.py
index 464dbde..a8980eb 100644
--- a/lesana/collection.py
+++ b/lesana/collection.py
@@ -1,3 +1,4 @@
+import decimal
import logging
import os
import uuid
@@ -56,6 +57,10 @@ class Entry(object):
data += ("{name}: |\n .\n".format(**field))
elif t == 'integer':
data += ("{name}: 0\n".format(**field))
+ elif t == 'float':
+ data += ("{name}: 0.0\n".format(**field))
+ elif t == 'decimal':
+ data += ("{name}: 0.00\n".format(**field))
elif t == 'list':
data += ("{name}: []\n".format(**field))
else:
@@ -105,6 +110,17 @@ class Entry(object):
value
),
})
+ elif t == 'decimal':
+ try:
+ decimal.Decimal(value)
+ except ValueError:
+ valid = False
+ errors.append({
+ 'field': field['name'],
+ 'error': 'Invalid value for decimal field: {}'.format(
+ value
+ ),
+ })
return valid, errors
def render(self, template, searchpath='.'):