Skip to content
Snippets Groups Projects
Commit 18f69d5f authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-745: added convenience method to validate any document against a template's schema

parent 0cface11
No related branches found
No related tags found
3 merge requests!634WIP: COBALT commissioning delta,!504TMSS-745: Responsive Telescope,!481Draft: SW-971 SW-973 SW-975: Various fixes to build LOFAR correctly.
......@@ -3,6 +3,8 @@ This file contains common constructs used by database models in other modules
"""
import logging
import typing
logger = logging.getLogger(__name__)
from django.db.models import Model, CharField, DateTimeField, IntegerField, UniqueConstraint
......@@ -167,6 +169,13 @@ class Template(NamedCommon):
# this template's schema has a schema of its own (usually the draft-06 meta schema). Validate it.
validate_json_against_its_schema(self.schema)
def validate_document(self, json_doc: typing.Union[str, dict]) -> bool:
'''validate the given json_doc against the template's schema
If no exception if thrown, then the given json_string validates against the given schema.
:raises SchemaValidationException if the json_string does not validate against the schema '''
validate_json_against_schema(json_doc, self.schema, cache=TemplateSchemaMixin._schema_cache, max_cache_age=TemplateSchemaMixin._MAX_SCHEMA_CACHE_AGE)
@property
def is_used(self) -> bool:
'''Is this template used by any of its related objects?'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment