forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
33 lines (26 loc) · 1.12 KB
/
forms.py
File metadata and controls
33 lines (26 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright The IETF Trust 2012-2020, All Rights Reserved
# -*- coding: utf-8 -*-
from django import forms
from django.core.exceptions import ValidationError
from django.template import Context
from ietf.dbtemplate.models import DBTemplate
from ietf.dbtemplate.template import PlainTemplate, RSTTemplate, DjangoTemplate
import debug # pyflakes:ignore
class DBTemplateForm(forms.ModelForm):
def clean_content(self):
try:
content = self.cleaned_data['content']
if self.instance.type.slug == 'rst':
RSTTemplate(content).render(Context({}))
elif self.instance.type.slug == 'django':
DjangoTemplate(content).render(Context({}))
elif self.instance.type.slug == 'plain':
PlainTemplate(content).render(Context({}))
else:
raise ValidationError("Unexpected DBTemplate.type.slug: %s" % self.type.slug)
except Exception as e:
raise ValidationError(e)
return content
class Meta:
model = DBTemplate
fields = ('content', )