# HG changeset patch # User Marcin Kuzminski # Date 2017-07-24 12:28:19 # Node ID 8462771d62a52f73d08d9915ef4c22ae88449711 # Parent 151fcf6c51ed61758913ef271ec2e4d7cb2feb94 core: use a custom filter for rendering all mako templates. - brings old pylons function that converted None into a empty markup diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -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') diff --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py --- a/rhodecode/lib/base.py +++ b/rhodecode/lib/base.py @@ -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