Files
mayan-edms/mayan/apps/templating/widgets.py
Roberto Rosario 466f15e154 Move template sandbox to its own app
Improve UI for the sandbox template textarea.

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
2019-11-11 02:59:26 -04:00

38 lines
1.0 KiB
Python

from __future__ import absolute_import, unicode_literals
from collections import OrderedDict
from django import forms
from mayan.apps.common.classes import ModelProperty
from mayan.apps.common.widgets import NamedMultiWidget
class TemplateWidget(NamedMultiWidget):
def __init__(self, attrs=None, **kwargs):
widgets = OrderedDict()
widgets['model_property'] = forms.widgets.Select()
widgets['template'] = forms.widgets.Textarea(
attrs={'rows': 5}
)
super(TemplateWidget, self).__init__(
widgets=widgets, attrs=attrs, **kwargs
)
def decompress(self, value):
choices = ModelProperty.get_choices_for(
model=self.attrs['model']
)
self.widgets['model_property'].choices = (
[('', '----')] + choices
)
return {
'model_property': None, 'template': value
}
def value_from_datadict(self, querydict, files, name):
template = querydict.get('{}_template'.format(name))
return template