From 292058dcd6f1259d34afca49e50336d7c255d446 Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Fri, 3 Jul 2015 10:10:28 +0200 Subject: [PATCH] Make sure all required properties are present when loading a field definition. --- src/formdefinition.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/formdefinition.py b/src/formdefinition.py index f9ce6f0..f52bdb5 100644 --- a/src/formdefinition.py +++ b/src/formdefinition.py @@ -30,6 +30,20 @@ class FormDefinition(object): self.submit_title = submit_title self.allowed_users = allowed_users + self.validate_field_defs(self.fields) + + def validate_field_defs(self, fields): + """ + Make sure all required properties are present when loading a field + definition. + """ + required = ['name', 'title', 'type'] + for field in fields: + for prop_name in required: + if not prop_name in field: + raise KeyError("Missing required property '{}' for field " + "'{}'".format(prop_name, str(field))) + def get_field_def(self, field_name): """ Return the field definition for `field_name`.