Call request.static_url directly from template
authorKarl O. Pinc <kop@karlpinc.com>
Thu, 19 Nov 2020 23:30:30 +0000 (17:30 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Thu, 19 Nov 2020 23:30:30 +0000 (17:30 -0600)
src/pgwui_common/pgwui_common.py
src/pgwui_common/templates/base.mak
tests/test_pgwui_common.py

index 9508b90b44f83d0605db835220dd75628ed565ee..5a76972bbcdcbf1e30bc5b7d4c7c14d8a2762a31 100644 (file)
@@ -33,9 +33,6 @@ def base_view(wrapped):
         '''
         response = wrapped(request)
         pgwui = response.get('pgwui', {})
-        url = pgwui.setdefault('url', dict())
-        url.setdefault('css',
-                       request.static_url('pgwui_common:static/pgwui.css'))
         route = pgwui.setdefault('route', dict())
         route.setdefault('home',
                          request.route_url('home'))
index 42d042bf0cc05ca364f7b8ea3e46bdb982fc620b..2a38acbd41c62932989a893761d6cb00fd1ff0a3 100644 (file)
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <%block name="meta_keywords" />
   <%block name="meta_description" />
-  <link rel="stylesheet" href="${pgwui['url']['css']}" type="text/css" />
+  <%block name="stylesheet_links">
+    <link rel="stylesheet"
+          href="${request.static_url('pgwui_common:static/pgwui.css')}"
+          type="text/css" />
+  </%block>
 </head>
 
 <body>
index bab7ff3571c3ea6a038d7160dfba965d63f3562e..4e3542e56a0e0e43504bbbc44cd12e3a43ce97af 100644 (file)
@@ -29,18 +29,15 @@ pytest_plugins = ("pgwui",)
 
 # Helper functions and constants
 
-CSS_URL = 'foo://bar/'
+FOO_URL = 'foo://bar/'
 
 
 def mock_view(request):
-    return {'pgwui': {'url': {'css': CSS_URL}}}
+    return {'pgwui': {'foo': FOO_URL}}
 
 
 def check_base_view_results(request, pgwui):
-    assert pgwui['url']['css'] == CSS_URL
-    url = (request.application_url
-           + pgwui_common.DEFAULT_HOME_ROUTE)
-    assert pgwui['route']['home'] == url
+    assert pgwui['foo'] == FOO_URL
 
 
 # Unit tests
@@ -51,10 +48,14 @@ def test_base_view_add(pyramid_request_config):
     def mock_view(request):
         return {}
 
+    request = get_current_request()
+    url = (request.application_url
+           + pgwui_common.DEFAULT_HOME_ROUTE)
+
     pgwui_common.includeme(pyramid_request_config)
     wrapper = pgwui_common.base_view(mock_view)
-    response = wrapper(get_current_request())
-    assert response['pgwui']['url']['css'][0:4] == 'http'
+    response = wrapper(request)
+    assert response['pgwui']['route']['home'] == url
 
 
 def test_base_view_default(pyramid_request_config):