diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py index ab1e8fc20ca9443ff68460d07168c67a5402089c..4f95a96b250d7cb1ea52c9196c4bcdbff17405d6 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py @@ -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?'''