allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kentontay...@apache.org
Subject [allura] 09/12: [#8273] Upgrade TG 2.3.2
Date Tue, 09 Apr 2019 17:02:44 GMT
This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit ee4d2cb4337842a8cb216c92c250c6bb3c885072
Author: Dave Brondsema <dave@brondsema.net>
AuthorDate: Fri Mar 29 17:40:47 2019 -0400

    [#8273] Upgrade TG 2.3.2
---
 Allura/allura/config/app_cfg.py                    | 30 ++++++++++++++++------
 .../tests/templates/jinja_master/test_lib.py       |  8 +++---
 requirements.txt                                   |  2 +-
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/Allura/allura/config/app_cfg.py b/Allura/allura/config/app_cfg.py
index cc26995..abd4076 100644
--- a/Allura/allura/config/app_cfg.py
+++ b/Allura/allura/config/app_cfg.py
@@ -33,13 +33,13 @@ convert them into boolean, for example, you should use the
 import logging
 from functools import partial
 
-import tg
+from tg import app_globals as g
+from tg.renderers.jinja import JinjaRenderer
 import jinja2
 import pylons
 from tg.configuration import AppConfig, config
 from routes import Mapper
 from webhelpers.html import literal
-
 import ew
 
 import allura
@@ -57,6 +57,7 @@ class ForgeConfig(AppConfig):
         self.package = allura
         self.renderers = ['json', 'genshi', 'mako', 'jinja']
         self.default_renderer = 'jinja'
+        self.register_rendering_engine(AlluraJinjaRenderer)
         self.use_sqlalchemy = False
         self.use_toscawidgets = False
         self.use_transaction_manager = False
@@ -64,6 +65,11 @@ class ForgeConfig(AppConfig):
         self.handle_status_codes = [403, 404]
         self.disable_request_extensions = True
 
+        # if left to True (default) would use crank.util.default_path_translator to convert
all URL punctuation to "_"
+        # which is convenient for /foo-bar to execute a "def foo_bar" method, but is a pretty
drastic change for us
+        # and makes many URLs be valid that we might not want like /foo*bar /foo@bar /foo:bar
+        self.dispatch_path_translator = None
+
     def after_init_config(self):
         config['tg.strict_tmpl_context'] = True
 
@@ -75,7 +81,11 @@ class ForgeConfig(AppConfig):
                     action='routes_placeholder')
         config['routes.map'] = map
 
-    def _setup_bytecode_cache(self):
+
+class AlluraJinjaRenderer(JinjaRenderer):
+
+    @classmethod
+    def _setup_bytecode_cache(cls):
         cache_type = config.get('jinja_bytecode_cache_type')
         bcc = None
         try:
@@ -92,8 +102,12 @@ class ForgeConfig(AppConfig):
                           " %s-backed bytecode cache for Jinja" % cache_type)
         return bcc
 
-    def setup_jinja_renderer(self):
-        bcc = self._setup_bytecode_cache()
+    @classmethod
+    def create(cls, config, app_globals):
+        # this has evolved over the age of allura, and upgrades of TG
+        # the parent JinjaRenderer logic is different, some may be better and hasn't been
incorporated into ours yet
+
+        bcc = cls._setup_bytecode_cache()
         jinja2_env = jinja2.Environment(
             loader=PackagePathLoader(),
             auto_reload=config.auto_reload_templates,
@@ -104,13 +118,13 @@ class ForgeConfig(AppConfig):
         jinja2_env.install_gettext_translations(pylons.i18n)
         jinja2_env.filters['filesizeformat'] = helpers.do_filesizeformat
         jinja2_env.filters['datetimeformat'] = helpers.datetimeformat
-        jinja2_env.filters['filter'] = lambda s,t=None: filter(t and jinja2_env.tests[t],
s)
+        jinja2_env.filters['filter'] = lambda s, t=None: filter(t and jinja2_env.tests[t],
s)
         jinja2_env.filters['nl2br'] = helpers.nl2br_jinja_filter
         jinja2_env.globals.update({'hasattr': hasattr})
-        config['tg.app_globals'].jinja2_env = jinja2_env
+        config['tg.app_globals'].jinja2_env = jinja2_env  # TG doesn't need this, but we
use g.jinja2_env a lot
         # Jinja's unable to request c's attributes without strict_c
         config['tg.strict_tmpl_context'] = True
-        self.render_functions.jinja = tg.render.render_jinja
+        return {'jinja': cls(jinja2_env)}
 
 
 class JinjaEngine(ew.TemplateEngine):
diff --git a/Allura/allura/tests/templates/jinja_master/test_lib.py b/Allura/allura/tests/templates/jinja_master/test_lib.py
index b818560..9421fe4 100644
--- a/Allura/allura/tests/templates/jinja_master/test_lib.py
+++ b/Allura/allura/tests/templates/jinja_master/test_lib.py
@@ -15,11 +15,11 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-from tg import config
+from tg import config, app_globals as g
 from mock import Mock
 from nose.tools import assert_equal
 
-from allura.config.app_cfg import ForgeConfig
+from allura.config.app_cfg import ForgeConfig, AlluraJinjaRenderer
 from alluratest.controller import setup_config_test
 
 
@@ -30,9 +30,7 @@ def strip_space(s):
 class TemplateTest(object):
     def setUp(self):
         setup_config_test()
-        forge_config = ForgeConfig()
-        forge_config.setup_jinja_renderer()
-        self.jinja2_env = config['tg.app_globals'].jinja2_env
+        self.jinja2_env = AlluraJinjaRenderer.create(config, g)['jinja'].jinja2_env
 
 
 class TestRelatedArtifacts(TemplateTest):
diff --git a/requirements.txt b/requirements.txt
index d4839ab..94c6dde 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -49,7 +49,7 @@ textile==2.1.5
 # dep of colander
 translationstring==1.3
 TimerMiddleware==0.4.4
-TurboGears2==2.3.1
+TurboGears2==2.3.2
 # dep of html5lib
 webencodings==0.5.1
 WebOb==1.3.1


Mime
View raw message