annotate, validate and add defaults to the JSON document in the model instance using the schema of the given template.
'''
try:
# fetch the actual JSON document and template-model-intstance
document=getattr(model,document_attr)
template=getattr(model,template_attr)
ifisinstance(document,str):
document=json.loads(document)
ifdocumentisnotNoneandtemplateisnotNone:
try:
ifisinstance(document,str):
document=json.loads(document)
# always annotate the json data document with a $schema URI to the schema that it is based on.
# this enables all users using this document (inside or outside of TMSS) to do their own validation and usage of editors which use the schema as UI template
document['$schema']=template.schema['$id']
except (KeyError,TypeError)ase:
except (KeyError,TypeError,AttributeError)ase:
raiseSchemaValidationException("Cannot set $schema in json_doc to the schema's $id.\nError: %s \njson_doc: %s\nschema: %s"%(str(e),document,template.schema))
# add defaults for missing properies, and validate on the fly
generator_doc=JSONField(null=True,help_text='Parameters for the generator (NULLable).')
generator_template=ForeignKey('GeneratorTemplate',on_delete=SET_NULL,null=True,help_text='Generator for the scheduling units in this set (NULLable).')
...
...
@@ -436,7 +444,7 @@ class SchedulingSet(NamedCommon):
project=ForeignKey('Project',related_name="scheduling_sets",on_delete=PROTECT,help_text='Project to which this scheduling set belongs.')# protected to avoid accidents
@@ -493,7 +501,7 @@ class SchedulingUnitBlueprint(NamedCommon):
draft=ForeignKey('SchedulingUnitDraft',related_name='scheduling_unit_blueprints',on_delete=CASCADE,help_text='Scheduling Unit Draft which this run instantiates.')
@@ -669,7 +677,7 @@ class TaskBlueprint(NamedCommon):
scheduling_unit_blueprint=ForeignKey('SchedulingUnitBlueprint',related_name='task_blueprints',on_delete=CASCADE,help_text='Scheduling Unit Blueprint to which this task belongs.')
@@ -769,7 +777,7 @@ class TaskRelationDraft(BasicCommon):
output_role=ForeignKey('TaskConnectorType',related_name='taskrelationdraft_output_roles',on_delete=CASCADE,help_text='Output connector type (what kind of data can be created as output).')