From 82cf88ee49464f9096728068d3f7930afbfb72d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 15 Jun 2016 15:59:20 +0200 Subject: [PATCH] Slight simplification of node form valdation, and better logging. --- pillar/application/__init__.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pillar/application/__init__.py b/pillar/application/__init__.py index edc68dc2..6cab3070 100644 --- a/pillar/application/__init__.py +++ b/pillar/application/__init__.py @@ -13,6 +13,8 @@ from eve import Eve from eve.auth import TokenAuth from eve.io.mongo import Validator +from application.utils import project_get_node_type + RFC1123_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT' @@ -53,26 +55,20 @@ class ValidateCustomFields(Validator): projects_collection = app.data.driver.db['projects'] lookup = {'_id': ObjectId(self.document['project'])} project = projects_collection.find_one(lookup) - node_type = next( - (item for item in project['node_types'] if item.get('name') \ - and item['name'] == self.document['node_type']), None) + node_type = project_get_node_type(project, self.document['node_type']) try: value = self.convert_properties(value, node_type['dyn_schema']) - except Exception, e: - log.debug("Error converting form properties", exc_info=True) + except Exception as e: + log.warning("Error converting form properties", exc_info=True) v = Validator(node_type['dyn_schema']) val = v.validate(value) if val: return True - else: - try: - print (val.errors) - except: - pass - self._error( - field, "Error validating properties") + + log.debug('Error validating properties for node %s: %s', self.document, v.errors) + self._error(field, "Error validating properties") # We specify a settings.py file because when running on wsgi we can't detect it