core: use a custom filter for rendering all mako templates.

- brings old pylons function that converted None into a empty markup
This commit is contained in:
Marcin Kuzminski 2017-07-24 14:28:19 +02:00
parent b253e2b02e
commit 67f8000683
2 changed files with 17 additions and 0 deletions

View file

@ -273,6 +273,11 @@ def includeme(config):
if asbool(settings.get('appenlight', 'false')):
config.include('appenlight_client.ext.pyramid_tween')
if not 'mako.default_filters' in settings:
# set custom default filters if we don't have it defined
settings['mako.imports'] = 'from rhodecode.lib.base import h_filter'
settings['mako.default_filters'] = 'h_filter'
# Includes which are required. The application would fail without them.
config.include('pyramid_mako')
config.include('pyramid_beaker')

View file

@ -27,6 +27,7 @@ controllers
import logging
import socket
import markupsafe
import ipaddress
import pyramid.threadlocal
@ -570,6 +571,17 @@ class BaseController(WSGIController):
return WSGIController.__call__(self, environ, start_response)
def h_filter(s):
"""
Custom filter for Mako templates. Mako by standard uses `markupsafe.escape`
we wrap this with additional functionality that converts None to empty
strings
"""
if s is None:
return markupsafe.Markup()
return markupsafe.escape(s)
class BaseRepoController(BaseController):
"""
Base class for controllers responsible for loading all needed data for