Skip to content

Commit

Permalink
Return '' when var_name is supplied, but set the value to None as app…
Browse files Browse the repository at this point in the history
…ropriate.

Signed-off-by: Martin Koistinen <mkoistinen@gmail.com>
  • Loading branch information
mkoistinen committed Feb 28, 2014
1 parent 59f6991 commit 3916025
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions cms/templatetags/cms_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 3916025

Please sign in to comment.