From 0b4c8242eeb6b7181ccc3251881fdc34cea63b5c Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 10 Dec 2019 22:31:46 -0400 Subject: [PATCH] Use TemplateField for the web link template Signed-off-by: Roberto Rosario --- HISTORY.rst | 1 + mayan/apps/web_links/forms.py | 11 +++++++++++ mayan/apps/web_links/models.py | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index d4a5198572..f5dfaec863 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -15,6 +15,7 @@ smart link views. - TemplateField shows the available variable in the help text automatically. +- Use TemplateField for the web link template. 3.3.4 (2019-12-09) ================== diff --git a/mayan/apps/web_links/forms.py b/mayan/apps/web_links/forms.py index e5e6beae69..85cc3ebb67 100644 --- a/mayan/apps/web_links/forms.py +++ b/mayan/apps/web_links/forms.py @@ -2,10 +2,21 @@ from __future__ import unicode_literals from django import forms +from mayan.apps.documents.models import Document +from mayan.apps.templating.fields import TemplateField + from .models import WebLink class WebLinkForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super(WebLinkForm, self).__init__(*args, **kwargs) + self.fields['template'] = TemplateField( + initial_help_text=self.fields['template'].help_text, + label=self.fields['template'].label, model=Document, + model_variable='document', required=True + ) + class Meta: fields = ('label', 'template', 'enabled') model = WebLink diff --git a/mayan/apps/web_links/models.py b/mayan/apps/web_links/models.py index 0284ff5a72..2bf79499f7 100644 --- a/mayan/apps/web_links/models.py +++ b/mayan/apps/web_links/models.py @@ -26,7 +26,7 @@ class WebLink(models.Model): template = models.TextField( help_text=_( 'Template that will be used to craft the final URL of the ' - 'web link. The {{ document }} variable is available to the template.' + 'web link.' ), verbose_name=_('Template') ) enabled = models.BooleanField(default=True, verbose_name=_('Enabled'))