From 5bd4b53d619ea14cd01a2e5adbfd1f2b8992ab9c Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Fri, 20 Sep 2019 12:33:29 +0200 Subject: new field type: decimal --- docs/field_types.rst | 2 ++ lesana/collection.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) 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='.'): -- cgit v1.2.3