Slight simplification of node form valdation, and better logging.

This commit is contained in:
Sybren A. Stüvel 2016-06-15 15:59:20 +02:00
parent a17bb969f9
commit 82cf88ee49

View File

@ -13,6 +13,8 @@ from eve import Eve
from eve.auth import TokenAuth from eve.auth import TokenAuth
from eve.io.mongo import Validator 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' 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'] projects_collection = app.data.driver.db['projects']
lookup = {'_id': ObjectId(self.document['project'])} lookup = {'_id': ObjectId(self.document['project'])}
project = projects_collection.find_one(lookup) project = projects_collection.find_one(lookup)
node_type = next( node_type = project_get_node_type(project, self.document['node_type'])
(item for item in project['node_types'] if item.get('name') \
and item['name'] == self.document['node_type']), None)
try: try:
value = self.convert_properties(value, node_type['dyn_schema']) value = self.convert_properties(value, node_type['dyn_schema'])
except Exception, e: except Exception as e:
log.debug("Error converting form properties", exc_info=True) log.warning("Error converting form properties", exc_info=True)
v = Validator(node_type['dyn_schema']) v = Validator(node_type['dyn_schema'])
val = v.validate(value) val = v.validate(value)
if val: if val:
return True return True
else:
try: log.debug('Error validating properties for node %s: %s', self.document, v.errors)
print (val.errors) self._error(field, "Error validating properties")
except:
pass
self._error(
field, "Error validating properties")
# We specify a settings.py file because when running on wsgi we can't detect it # We specify a settings.py file because when running on wsgi we can't detect it