Move template sandbox to its own app
Improve UI for the sandbox template textarea. Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
37
mayan/apps/templating/widgets.py
Normal file
37
mayan/apps/templating/widgets.py
Normal file
@@ -0,0 +1,37 @@
|
||||
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
|
||||
Reference in New Issue
Block a user