Use TemplateField for Index expression field
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -129,6 +129,8 @@
|
||||
now get the permission inheritance from their base models.
|
||||
- Update common.http.URL to allow passing a query dictionary.
|
||||
- Add the document template sandbox feature.
|
||||
- Use the generic TemplateField for the expression field
|
||||
of index tree templates.
|
||||
|
||||
3.2.10 (2019-XX-XX)
|
||||
===================
|
||||
|
||||
@@ -1,52 +1,16 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django import forms
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.common.classes import ModelProperty
|
||||
from mayan.apps.common.forms import FilteredSelectionForm
|
||||
from mayan.apps.documents.models import Document
|
||||
from mayan.apps.templating.fields import TemplateField
|
||||
|
||||
from .models import Index, IndexTemplateNode
|
||||
from .permissions import permission_document_indexing_rebuild
|
||||
|
||||
|
||||
class DocumentTemplateSandboxForm(forms.Form):
|
||||
template = forms.CharField(
|
||||
help_text=_(
|
||||
'The template string to be evaluated. The current document '
|
||||
'is available as the {{ document }} variable.'
|
||||
), label=_('Template'), widget=forms.widgets.Textarea(
|
||||
attrs={'rows': 5}
|
||||
)
|
||||
)
|
||||
result = forms.CharField(
|
||||
help_text=_('Resulting text from the evaluated template.'),
|
||||
label=_('Result'), required=False, widget=forms.widgets.Textarea(
|
||||
attrs={'rows': 5}
|
||||
)
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DocumentTemplateSandboxForm, self).__init__(*args, **kwargs)
|
||||
self.fields['template'].help_text = ' '.join(
|
||||
[
|
||||
force_text(self.fields['template'].help_text),
|
||||
force_text(
|
||||
_(
|
||||
'Use Django\'s default templating language '
|
||||
'(https://docs.djangoproject.com/en/1.11/ref/templates/builtins/)'
|
||||
),
|
||||
),
|
||||
'<br>',
|
||||
ModelProperty.get_help_text_for(
|
||||
model=Document, show_name=True
|
||||
).replace('\n', '<br>')
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class IndexTemplateFilteredForm(FilteredSelectionForm):
|
||||
class Meta:
|
||||
allow_multiple = True
|
||||
@@ -66,14 +30,9 @@ class IndexTemplateNodeForm(forms.ModelForm):
|
||||
super(IndexTemplateNodeForm, self).__init__(*args, **kwargs)
|
||||
self.fields['index'].widget = forms.widgets.HiddenInput()
|
||||
self.fields['parent'].widget = forms.widgets.HiddenInput()
|
||||
self.fields['expression'].help_text = ' '.join(
|
||||
[
|
||||
force_text(self.fields['expression'].help_text),
|
||||
'<br>',
|
||||
ModelProperty.get_help_text_for(
|
||||
model=Document, show_name=True
|
||||
).replace('\n', '<br>')
|
||||
]
|
||||
self.fields['expression'] = TemplateField(
|
||||
label=_('Template'), model=Document,
|
||||
model_variable='document', required=False
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.template import (
|
||||
Context, RequestContext, Template, TemplateSyntaxError
|
||||
)
|
||||
from django.template import RequestContext
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils.html import mark_safe
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext
|
||||
@@ -15,8 +12,6 @@ from mayan.apps.common.generics import (
|
||||
AddRemoveView, ConfirmView, FormView, SingleObjectCreateView,
|
||||
SingleObjectDeleteView, SingleObjectEditView, SingleObjectListView
|
||||
)
|
||||
from mayan.apps.common.http import URL
|
||||
from mayan.apps.common.mixins import ExternalObjectMixin
|
||||
from mayan.apps.documents.events import event_document_type_edited
|
||||
from mayan.apps.documents.models import Document, DocumentType
|
||||
from mayan.apps.documents.permissions import (
|
||||
|
||||
Reference in New Issue
Block a user