From 3916025576f83e04414c411fd77340304a251cc6 Mon Sep 17 00:00:00 2001 From: Martin Koistinen Date: Fri, 28 Feb 2014 15:55:17 +0200 Subject: [PATCH] Return '' when var_name is supplied, but set the value to None as appropriate. Signed-off-by: Martin Koistinen --- cms/templatetags/cms_tags.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cms/templatetags/cms_tags.py b/cms/templatetags/cms_tags.py index 28a7df65ea0..a04dd14665a 100644 --- a/cms/templatetags/cms_tags.py +++ b/cms/templatetags/cms_tags.py @@ -111,7 +111,7 @@ def _get_page_by_untyped_arg(page_lookup, request, site_id): return None # -# This is borrowed/adapted from https://github.com/okfn/foundation +# This is borrowed from https://github.com/okfn/foundation # class PageUrl(AsTag): name = 'page_url' @@ -131,6 +131,9 @@ class PageUrl(AsTag): # If varname is not provided, and the specified page cannot be found, we # pass through the Page.DoesNotExist exception. # + # If varname is provided, we swallow the exception and just set the value + # to None. + # def render_tag(self, context, **kwargs): varname = kwargs.pop(self.varname_name) try: @@ -144,24 +147,24 @@ def render_tag(self, context, **kwargs): if varname: context[varname] = value return '' + return value - # - # If varname is provided, we swallow the exception and just set the value - # to an empty string. - # def get_value(self, context, page_lookup, lang, site): from django.core.cache import cache + site_id = get_site_id(site) request = context.get('request', False) if not request: - return '' + return None if lang is None: lang = get_language_from_request(request) + cache_key = _get_cache_key('page_url', page_lookup, lang, site_id) + \ '_type:absolute_url' + url = cache.get(cache_key) if not url: @@ -172,7 +175,7 @@ def get_value(self, context, page_lookup, lang, site): get_cms_setting('CACHE_DURATIONS')['content']) if url: return url - return '' + return None register.tag(PageUrl)