Added template tags functionality to schema/layout (to allow specifying default values based on event)

This commit is contained in:
David Taylor
2015-08-13 15:42:39 +03:00
committed by Tom Price
parent bdb7941579
commit 0aa2c62af8
3 changed files with 33 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ import datetime
from RIGS.models import RevisionMixin
from django.template import Context,Template
@reversion.register
class Type(models.Model, RevisionMixin):
@@ -73,6 +74,28 @@ class Form(models.Model, RevisionMixin):
data = models.TextField(blank=False, null=False, default="{}")
@property
def renderedSchema(self):
template = Template(self.schema.schema)
context = Context({
"event": self.event, # allow stuff to be auto-filled
"SfCurrentIndex": "{{ $index +1 }}" # Convenience for schemaform array index
})
return template.render(context)
@property
def renderedLayout(self):
template = Template(self.schema.layout)
context = Context({
"event": self.event, # allow stuff to be auto-filled
"SfCurrentIndex": "{{ $index +1 }}" # Convenience for schemaform array index
})
return template.render(context)
def clean(self):
try:
jsonData = json.loads(self.data)
@@ -89,7 +112,6 @@ class Form(models.Model, RevisionMixin):
except jsonschema.ValidationError as e: #raise a django exception
raise ValidationError('Data is not valid, cannot save: '+e.message)
def save(self, *args, **kwargs):
"""Call :meth:`full_clean` before saving."""
self.full_clean()