mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-19 14:32:16 +00:00
Added template tags functionality to schema/layout (to allow specifying default values based on event)
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user