Added dbtemplate validation to the class, to make sure one cannot enter invalid DBtemplates through the admin.
- Legacy-Id: 16100
This commit is contained in:
parent
a8086369ec
commit
a60ac983d7
|
@ -5,6 +5,7 @@ from ietf.dbtemplate.models import DBTemplate
|
|||
|
||||
class DBTemplateAdmin(admin.ModelAdmin):
|
||||
list_display = ('title', 'path',)
|
||||
search_fields = ('title', 'path', )
|
||||
ordering = ('path', )
|
||||
|
||||
admin.site.register(DBTemplate, DBTemplateAdmin)
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright The IETF Trust 2012-2019, All Rights Reserved
|
||||
from __future__ import unicode_literals, print_function
|
||||
|
||||
|
||||
from django.db import models
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.template import Context
|
||||
|
||||
from ietf.group.models import Group
|
||||
from ietf.name.models import DBTemplateTypeName
|
||||
|
@ -22,3 +29,18 @@ class DBTemplate(models.Model):
|
|||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
||||
def clean(self):
|
||||
from ietf.dbtemplate.template import PlainTemplate, RSTTemplate, DjangoTemplate
|
||||
try:
|
||||
if self.type.slug == 'rst':
|
||||
RSTTemplate(self.content).render(Context({}))
|
||||
elif self.type.slug == 'django':
|
||||
DjangoTemplate(self.content).render(Context({}))
|
||||
elif self.type.slug == 'plain':
|
||||
PlainTemplate(self.content).render(Context({}))
|
||||
else:
|
||||
raise ValidationError("Unexpected DBTemplate.type.slug: %s" % self.type.slug)
|
||||
except Exception, e:
|
||||
raise ValidationError(e)
|
||||
|
||||
|
|
Loading…
Reference in a new issue