From 975e0a4087b215e086613d01ca2cfd727ae05ad3 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Tue, 21 Sep 2010 14:25:14 +0200 Subject: [PATCH] Added DBTEMPLATES_AUTO_POPULATE_CONTENT setting to be able to disable to auto populating of template content. --- dbtemplates/admin.py | 9 ++++++--- dbtemplates/models.py | 2 +- dbtemplates/settings.py | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index 58d2545..1b0924b 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -49,6 +49,11 @@ if settings.USE_CODEMIRROR: else: TemplateContentTextArea = forms.Textarea +if settings.AUTO_POPULATE_CONTENT: + content_help_text = _("Leaving this empty causes Django to look for a " + "template with the given name and populate this field with its content.") +else: + content_help_text = "" class TemplateAdminForm(forms.ModelForm): """ @@ -56,9 +61,7 @@ class TemplateAdminForm(forms.ModelForm): """ content = forms.CharField( widget=TemplateContentTextArea({'rows': '24'}), - help_text=_("Leaving this empty causes Django to look for a template " - "with the given name and populate this field with its content."), - required=False) + help_text=content_help_text, required=False) class Meta: model = Template diff --git a/dbtemplates/models.py b/dbtemplates/models.py index a910ec2..565433b 100644 --- a/dbtemplates/models.py +++ b/dbtemplates/models.py @@ -63,7 +63,7 @@ class Template(models.Model): self.last_changed = datetime.now() # If content is empty look for a template with the given name and # populate the template instance with its content. - if not self.content: + if settings.AUTO_POPULATE_CONTENT and not self.content: self.populate() super(Template, self).save(*args, **kwargs) diff --git a/dbtemplates/settings.py b/dbtemplates/settings.py index 7955c9b..f286a01 100644 --- a/dbtemplates/settings.py +++ b/dbtemplates/settings.py @@ -6,6 +6,8 @@ CACHE_BACKEND = getattr(settings, 'DBTEMPLATES_CACHE_BACKEND', None) ADD_DEFAULT_SITE = getattr(settings, 'DBTEMPLATES_ADD_DEFAULT_SITE', True) +AUTO_POPULATE_CONTENT = getattr(settings, 'DBTEMPLATES_AUTO_POPULATE_CONTENT', True) + MEDIA_PREFIX = getattr(settings, 'DBTEMPLATES_MEDIA_PREFIX', os.path.join(settings.MEDIA_ROOT, 'dbtemplates')) @@ -15,3 +17,4 @@ if USE_REVERSION and 'reversion'not in settings.INSTALLED_APPS: raise ImproperlyConfigured("Please add reversion to your INSTALLED_APPS setting to make use of it in dbtemplates.") USE_CODEMIRROR = getattr(settings, 'DBTEMPLATES_USE_CODEMIRROR', False) +