Use TemplateField for smart links
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
- TemplateField shows the available variable in the help text
|
- TemplateField shows the available variable in the help text
|
||||||
automatically.
|
automatically.
|
||||||
- Use TemplateField for the web link template.
|
- Use TemplateField for the web link template.
|
||||||
|
- Use TemplateField for smart links.
|
||||||
|
|
||||||
3.3.4 (2019-12-09)
|
3.3.4 (2019-12-09)
|
||||||
==================
|
==================
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
|
|
||||||
from mayan.apps.common.classes import ModelField, ModelProperty
|
from mayan.apps.common.classes import ModelField, ModelProperty
|
||||||
from mayan.apps.documents.models import Document
|
from mayan.apps.documents.models import Document
|
||||||
|
from mayan.apps.templating.fields import TemplateField
|
||||||
|
|
||||||
from .models import SmartLink, SmartLinkCondition
|
from .models import SmartLink, SmartLinkCondition
|
||||||
|
|
||||||
@@ -13,13 +14,10 @@ from .models import SmartLink, SmartLinkCondition
|
|||||||
class SmartLinkForm(forms.ModelForm):
|
class SmartLinkForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(SmartLinkForm, self).__init__(*args, **kwargs)
|
super(SmartLinkForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['dynamic_label'].help_text = ' '.join(
|
self.fields['dynamic_label'] = TemplateField(
|
||||||
[
|
initial_help_text=self.fields['dynamic_label'].help_text,
|
||||||
force_text(self.fields['dynamic_label'].help_text),
|
label=self.fields['dynamic_label'].label, model=Document,
|
||||||
ModelProperty.get_help_text_for(
|
model_variable='document', required=False
|
||||||
model=Document, show_name=True
|
|
||||||
).replace('\n', '<br>')
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -35,13 +33,10 @@ class SmartLinkConditionForm(forms.ModelForm):
|
|||||||
model=Document,
|
model=Document,
|
||||||
), label=_('Foreign document field')
|
), label=_('Foreign document field')
|
||||||
)
|
)
|
||||||
self.fields['expression'].help_text = ' '.join(
|
self.fields['expression'] = TemplateField(
|
||||||
[
|
initial_help_text=self.fields['expression'].help_text,
|
||||||
force_text(self.fields['expression'].help_text),
|
label=self.fields['expression'].label, model=Document,
|
||||||
ModelProperty.get_help_text_for(
|
model_variable='document', required=False
|
||||||
model=Document, show_name=True
|
|
||||||
).replace('\n', '<br>')
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -28,10 +28,8 @@ class SmartLink(models.Model):
|
|||||||
)
|
)
|
||||||
dynamic_label = models.CharField(
|
dynamic_label = models.CharField(
|
||||||
blank=True, max_length=96, help_text=_(
|
blank=True, max_length=96, help_text=_(
|
||||||
'Enter a template to render. '
|
'Use this field to show a unique label depending on the '
|
||||||
'Use Django\'s default templating language '
|
'document from which the smart link is being accessed.'
|
||||||
'(https://docs.djangoproject.com/en/1.11/ref/templates/builtins/). '
|
|
||||||
'The {{ document }} context variable is available.'
|
|
||||||
), verbose_name=_('Dynamic label')
|
), verbose_name=_('Dynamic label')
|
||||||
)
|
)
|
||||||
enabled = models.BooleanField(default=True, verbose_name=_('Enabled'))
|
enabled = models.BooleanField(default=True, verbose_name=_('Enabled'))
|
||||||
@@ -155,7 +153,7 @@ class SmartLink(models.Model):
|
|||||||
class ResolvedSmartLink(SmartLink):
|
class ResolvedSmartLink(SmartLink):
|
||||||
"""
|
"""
|
||||||
Proxy model to represent an already resolved smart link. Used for easier
|
Proxy model to represent an already resolved smart link. Used for easier
|
||||||
colums registration.
|
columns registration.
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
@@ -186,10 +184,8 @@ class SmartLinkCondition(models.Model):
|
|||||||
operator = models.CharField(choices=OPERATOR_CHOICES, max_length=16)
|
operator = models.CharField(choices=OPERATOR_CHOICES, max_length=16)
|
||||||
expression = models.TextField(
|
expression = models.TextField(
|
||||||
help_text=_(
|
help_text=_(
|
||||||
'Enter a template to render. '
|
'The expression using document properties to be evaluated '
|
||||||
'Use Django\'s default templating language '
|
'against the foreign document field.'
|
||||||
'(https://docs.djangoproject.com/en/1.11/ref/templates/builtins/). '
|
|
||||||
'The {{ document }} context variable is available.'
|
|
||||||
), verbose_name=_('Expression')
|
), verbose_name=_('Expression')
|
||||||
)
|
)
|
||||||
negated = models.BooleanField(
|
negated = models.BooleanField(
|
||||||
|
|||||||
Reference in New Issue
Block a user