[Kimchi-devel] [PATCH] [Wok] Bug fix #1109: Specify Content-Type for SVG files

Aline Manera alinefm at linux.vnet.ibm.com
Mon Apr 3 22:57:25 UTC 2017


Some systems do not have mimetype specified for SVG files which prevents
SVG files to be loaded on Wok UI.

Fix that and also set UIConfig for all plugins to share the same
configuration.

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 src/wok/config.py.in    | 41 +++++++++++++++++++++++++++--------------
 tests/test_config.py.in |  1 +
 2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/src/wok/config.py.in b/src/wok/config.py.in
index c2bcc28..9fd39d9 100644
--- a/src/wok/config.py.in
+++ b/src/wok/config.py.in
@@ -159,7 +159,7 @@ class PluginPaths(Paths):
 class UIConfig(dict):
     def __init__(self, paths):
         ui_configs = {}
-        for sub_dir in ('css', 'js', 'libs', 'images'):
+        for sub_dir in ('css', 'js', 'images'):
             ui_configs['/' + sub_dir] = {
                 'tools.staticdir.on': True,
                 'tools.staticdir.dir': os.path.join(paths.ui_dir, sub_dir),
@@ -169,17 +169,10 @@ class UIConfig(dict):
                 ui_configs['/' + sub_dir].update({
                     'tools.expires.on': True,
                     'tools.expires.secs': CACHEEXPIRES})
-
-        for font, files in FONT_FILES.iteritems():
-            font_dir = getattr(paths, "%s_dir" % font)
-            for filename in files:
-                font_file = os.path.join(font_dir, filename)
-                if os.path.exists(font_file):
-                    ui_configs['/fonts/%s' % filename] = {
-                        'tools.staticfile.on': True,
-                        'tools.staticfile.filename': font_file,
-                        'tools.wokauth.on': False,
-                        'tools.nocache.on': False}
+            else:
+                ui_configs['/' + sub_dir].update(
+                    {'tools.staticdir.content_types':
+                        {'svg': 'image/svg+xml'}})
 
         self.update(ui_configs)
 
@@ -237,8 +230,27 @@ class WokConfig(dict):
             'tools.staticdir.dir': os.path.join(paths.ui_dir,
                                                 'pages/help')
         },
+        '/libs': {
+            'tools.staticdir.on': True,
+            'tools.staticdir.dir': os.path.join(paths.ui_dir, 'libs'),
+            'tools.wokauth.on': False,
+            'tools.nocache.on': False,
+            'tools.expires.on': True,
+            'tools.expires.secs': CACHEEXPIRES
+        }
     }
 
+    for font, files in FONT_FILES.iteritems():
+        font_dir = getattr(paths, "%s_dir" % font)
+        for filename in files:
+            font_file = os.path.join(font_dir, filename)
+            if os.path.exists(font_file):
+                wok_config['/fonts/%s' % filename] = {
+                    'tools.staticfile.on': True,
+                    'tools.staticfile.filename': font_file,
+                    'tools.wokauth.on': False,
+                    'tools.nocache.on': False}
+
     def __init__(self):
         super(WokConfig, self).__init__(self)
         self.update(self.wok_config)
@@ -248,6 +260,7 @@ class WokConfig(dict):
 class PluginConfig(dict):
     def __init__(self, plugin_name):
         super(PluginConfig, self).__init__(self)
+        paths = PluginPaths(plugin_name)
         plugin_config = {
             '/': {
                 'tools.trailing_slash.on': False,
@@ -264,10 +277,10 @@ class PluginConfig(dict):
             '/ui/config/tab-ext.xml': {
                 'tools.staticfile.on': True,
                 'tools.staticfile.filename':
-                os.path.join(PluginPaths(plugin_name).ui_dir,
-                             'config/tab-ext.xml'),
+                os.path.join(paths.ui_dir, 'config/tab-ext.xml'),
                 'tools.nocache.on': True}}
         self.update(plugin_config)
+        self.update(UIConfig(paths))
 
 
 def _get_config():
diff --git a/tests/test_config.py.in b/tests/test_config.py.in
index a4d65bb..31dd1b8 100644
--- a/tests/test_config.py.in
+++ b/tests/test_config.py.in
@@ -147,6 +147,7 @@ class ConfigTests(unittest.TestCase):
                 'tools.wokauth.on': False,
                 'tools.nocache.on': False,
                 'tools.staticdir.dir': '%s/ui/images' % paths.prefix,
+                'tools.staticdir.content_types': {'svg': 'image/svg+xml'},
                 'tools.staticdir.on': True
             },
             '/fonts/fontawesome-webfont.ttf': {
-- 
2.9.3



More information about the Kimchi-devel mailing list