From 6116236ed9a2bf245df2f34361431fb2515b54ab Mon Sep 17 00:00:00 2001 From: Pavel Puchkin Date: Wed, 18 Apr 2012 18:56:53 +1100 Subject: [PATCH 1/4] `*_SAVE_AS` = None fix Ability to disable creating some files when their `_SAVE_AS` setting is set to none-value. Mostly for disabling creating of `authors` stuff (when there only one user, see #320 for details) --- pelican/contents.py | 3 ++- pelican/writers.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pelican/contents.py b/pelican/contents.py index 593822a9..8174f05a 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -183,7 +183,8 @@ class URLWrapper(object): def _from_settings(self, key): setting = "%s_%s" % (self.__class__.__name__.upper(), key) - return unicode(self.settings[setting]).format(**self.as_dict()) + value = self.settings[setting] or '' + return unicode(value).format(**self.as_dict()) url = property(functools.partial(_from_settings, key='URL')) save_as = property(functools.partial(_from_settings, key='SAVE_AS')) diff --git a/pelican/writers.py b/pelican/writers.py index faca46bd..058be333 100644 --- a/pelican/writers.py +++ b/pelican/writers.py @@ -99,6 +99,8 @@ class Writer(object): :param **kwargs: additional variables to pass to the templates """ + if not name: return + def _write_file(template, localcontext, output_path, name): """Render the template write the file.""" old_locale = locale.setlocale(locale.LC_ALL) From 55d7cf438b7586b05cd519184f827353c10a3864 Mon Sep 17 00:00:00 2001 From: Pavel Puchkin Date: Wed, 18 Apr 2012 19:04:32 +1100 Subject: [PATCH 2/4] Note in docs about previous commit --- docs/settings.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/settings.rst b/docs/settings.rst index 427795c2..af5f94dd 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -142,6 +142,9 @@ Setting name (default value) what does it do? `TAG_SAVE_AS` ('tag/{name}.html') The location to save the tag page. ================================================ ===================================================== +Note: when any of `*_SAVE_AS` setting is set to none-value (including an empty string), files will not be +created. + Timezone -------- From 9dcf612f9dfae01b1a65864660c289a0ac254707 Mon Sep 17 00:00:00 2001 From: Pavel Puchkin Date: Wed, 18 Apr 2012 23:07:57 +1100 Subject: [PATCH 3/4] Fixes after review --- docs/settings.rst | 3 +-- pelican/contents.py | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index af5f94dd..9cae8111 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -142,8 +142,7 @@ Setting name (default value) what does it do? `TAG_SAVE_AS` ('tag/{name}.html') The location to save the tag page. ================================================ ===================================================== -Note: when any of `*_SAVE_AS` setting is set to none-value (including an empty string), files will not be -created. +Note: when any of `*_SAVE_AS` is set to False, files will not be created. Timezone -------- diff --git a/pelican/contents.py b/pelican/contents.py index 8174f05a..506c4c02 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -183,7 +183,10 @@ class URLWrapper(object): def _from_settings(self, key): setting = "%s_%s" % (self.__class__.__name__.upper(), key) - value = self.settings[setting] or '' + value = self.settings[setting] + value = value is not False and value or '' # change to '' only False + if value == '': + logger.warning(u'%s is disabled' % setting) return unicode(value).format(**self.as_dict()) url = property(functools.partial(_from_settings, key='URL')) From 898ac3808f933e33f458822bb77e3f28d0623fc0 Mon Sep 17 00:00:00 2001 From: Pavel Puchkin Date: Fri, 20 Apr 2012 11:28:00 +1100 Subject: [PATCH 4/4] Last fix? --- pelican/contents.py | 9 +++++---- pelican/writers.py | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index 506c4c02..ba374ba1 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -184,10 +184,11 @@ class URLWrapper(object): def _from_settings(self, key): setting = "%s_%s" % (self.__class__.__name__.upper(), key) value = self.settings[setting] - value = value is not False and value or '' # change to '' only False - if value == '': - logger.warning(u'%s is disabled' % setting) - return unicode(value).format(**self.as_dict()) + if not isinstance(value, (str, unicode)): + logger.warning(u'%s is set to %s' % (setting, value)) + return value + else: + return unicode(value).format(**self.as_dict()) url = property(functools.partial(_from_settings, key='URL')) save_as = property(functools.partial(_from_settings, key='SAVE_AS')) diff --git a/pelican/writers.py b/pelican/writers.py index 058be333..6eb00d7e 100644 --- a/pelican/writers.py +++ b/pelican/writers.py @@ -99,7 +99,11 @@ class Writer(object): :param **kwargs: additional variables to pass to the templates """ - if not name: return + if name is False: + return + elif not name: + # other stuff, just return for now + return def _write_file(template, localcontext, output_path, name): """Render the template write the file."""