From e442317238baec9b18b832cacf84bec67d11226e Mon Sep 17 00:00:00 2001
From: Renaud Le Gac <renaud.legac@free.fr>
Date: Thu, 31 Mar 2011 20:01:29 +0000
Subject: [PATCH] Replace the function get_extjs_path by get_plugin_path.

---
 modules/plugin_dbui/__init__.py |  6 +++---
 modules/plugin_dbui/helper.py   | 32 +++++++++++++++++++-------------
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/modules/plugin_dbui/__init__.py b/modules/plugin_dbui/__init__.py
index da8f052f..1a363393 100644
--- a/modules/plugin_dbui/__init__.py
+++ b/modules/plugin_dbui/__init__.py
@@ -9,9 +9,9 @@ from fieldmodifier import FieldModifier
 from foreignfield import ForeignField
 from formmodifier import configure_forms, FormModifier
 from gridmodifier import configure_grids, GridModifier
-from helper import (get_extjs_path,
-                    get_js_files, 
-                    get_language, 
+from helper import (get_js_files, 
+                    get_language,
+                    get_plugin_path,
                     get_reference_paths, 
                     get_script_path)
 from mapper import map_default, map_tabpanel
diff --git a/modules/plugin_dbui/helper.py b/modules/plugin_dbui/helper.py
index 4000810d..f40bddf4 100644
--- a/modules/plugin_dbui/helper.py
+++ b/modules/plugin_dbui/helper.py
@@ -52,28 +52,34 @@ def encode_field(*args):
     return ''.join([el[0].upper()+el[1:].lower() for el in args if len(el)])
 
 
-def get_extjs_path(environment):
-    """Helper function returning the local path of the ExtJS plugin.
-    It is defined with respect to the application directory.
-
+def get_plugin_path(environment, plugin_name):
+    """Helper function returning the local path of the plugin name:
+    plugin_extjs, plugin_mathjax, ...
+    The local path defined with respect to the application directory.
+   
+    The function return the path of the first directory starting with
+    plugin_name. It is useful to handle plugin with a version number 
+    like plugin_extjs_3.3.2.
+    
     The dictionary environment contains the keys request, response, 
     session, plugins, ....
     
     Raise the exception HTTP(500) if the plugin is not found.
     
     """
-    application = environment['request'].application
-    
-    # check the absolute path on the server
-    server_path = os.path.join('applications', application)
-    path = os.path.join(server_path, 'static', 'plugin_extjs')
-    if not os.path.exists(path):
-        raise HTTP(500, 'The plugin ExtJS is not install !')
+    server_path, client_path = get_reference_paths(environment)
 
-    # return the local path
-    return os.path.join(os.path.sep, application, 'static', 'plugin_extjs')
+    # look for the full name of the plugin directory
+    p_static = os.path.join(server_path, 'static')
+    for el in os.listdir(p_static):
+        if os.path.isdir(os.path.join(p_static, el)):
+            if el.startswith(plugin_name):
+                return os.path.join(client_path, 'static', el)
 
+    # Nothing found
+    raise HTTP(500, 'The plugin %s is not install !' % plugin_name)
 
+    
 def get_js_files(server_path, client_path, directory):
     """Return a list of javascript files stored in the directory.
     The alphabetic order is preserved.
-- 
GitLab