From 579653f574288461755b2857772ae085a11bed6a Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <renaud.legac@free.fr> Date: Wed, 21 Dec 2011 21:18:41 +0100 Subject: [PATCH] Modified helper functions - remove environment argumenst and used gluon.current instead. - add is_mathjax ans used it. --- controllers/plugin_dbui.py | 20 ++++++------ modules/plugin_dbui/__init__.py | 1 + modules/plugin_dbui/helper.py | 56 +++++++++++++++------------------ modules/plugin_dbui/navtree.py | 13 ++++++-- 4 files changed, 47 insertions(+), 43 deletions(-) diff --git a/controllers/plugin_dbui.py b/controllers/plugin_dbui.py index b9382e39..4326cd48 100644 --- a/controllers/plugin_dbui.py +++ b/controllers/plugin_dbui.py @@ -108,14 +108,14 @@ def debug(): """ # check the presence of the ExtJS and MathJax plugins dbui = local_import('plugin_dbui') - pextjs = dbui.get_plugin_path(globals(), 'plugin_extjs') - pmathjax = dbui.get_plugin_path(globals(), 'plugin_mathjax') + pextjs = dbui.get_plugin_path('plugin_extjs') + pmathjax = dbui.get_plugin_path('plugin_mathjax') # internationalization (fr, fr-fr, fr-ca, ...) - lg = dbui.get_language(globals()) + lg = dbui.get_language() # dbui javascript source code -- respect the alphabetic order - server_path, client_path = dbui.get_reference_paths(globals()) + server_path, client_path = dbui.get_reference_paths() directory = os.path.join('static', 'plugin_dbui', 'src') jsfiles = dbui.get_js_files(server_path, client_path, directory) @@ -127,7 +127,7 @@ def debug(): response.files.extend(jsfiles) # main script - pscript = dbui.get_script_path(globals()) + pscript = dbui.get_script_path(plugins.dbui.script_path) response.files.append(pscript) # switch ON the debug mode on the server side @@ -214,14 +214,14 @@ def index(): """ # check the presence of the ExtJS and MathJax plugins dbui = local_import('plugin_dbui') - pextjs = dbui.get_plugin_path(globals(), 'plugin_extjs') - pmathjax = dbui.get_plugin_path(globals(), 'plugin_mathjax') + pextjs = dbui.get_plugin_path('plugin_extjs') + pmathjax = dbui.get_plugin_path('plugin_mathjax') # internationalization (fr, fr-fr, fr-ca, ...) - lg = dbui.get_language(globals()) + lg = dbui.get_language() # compressed version of the user library - server_path, client_path = dbui.get_reference_paths(globals()) + server_path, client_path = dbui.get_reference_paths() if plugins.dbui.user_libmin: path = os.path.join(server_path, plugins.dbui.user_libmin) @@ -230,7 +230,7 @@ def index(): response.files.append(libmin) # main script - pscript = dbui.get_script_path(globals()) + pscript = dbui.get_script_path(plugins.dbui.script_path) response.files.append(pscript) # switch off the debug mode on the server side diff --git a/modules/plugin_dbui/__init__.py b/modules/plugin_dbui/__init__.py index 6b6f5818..2102222d 100755 --- a/modules/plugin_dbui/__init__.py +++ b/modules/plugin_dbui/__init__.py @@ -18,6 +18,7 @@ from helper import (get_field_validators, get_set_field, get_where_query, is_foreign_field, + is_mathjax, is_set_field, is_table_with_foreign_fields) from mapper import map_default, map_tabpanel diff --git a/modules/plugin_dbui/helper.py b/modules/plugin_dbui/helper.py index 87b9e4a0..a4622738 100644 --- a/modules/plugin_dbui/helper.py +++ b/modules/plugin_dbui/helper.py @@ -7,6 +7,7 @@ __author__ = "R. Le Gac" import re import os +from gluon import current from gluon.http import HTTP from gluon.validators import (IS_DATE_IN_RANGE, IS_DATETIME_IN_RANGE, @@ -142,15 +143,12 @@ def get_js_files(server_path, client_path, directory): return li -def get_language(environment): +def get_language(): """Helper method returning the application language compliant with the ExtJS local file name. - - The dictionary environment contains the keys request, response, - session, plugins, .... """ - lg = environment['T'].accepted_language + lg = current.T.accepted_language # HTML tag for language: primary-dialect # Extract the primary language and ignore dialect @@ -161,7 +159,7 @@ def get_language(environment): return lg -def get_plugin_path(environment, plugin_name): +def get_plugin_path(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. @@ -170,13 +168,10 @@ def get_plugin_path(environment, plugin_name): 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, .... - Return None if the plugin is not found. """ - server_path, client_path = get_reference_paths(environment) + server_path, client_path = get_reference_paths() # look for the full name of the plugin directory p_static = os.path.join(server_path, 'static') @@ -189,17 +184,12 @@ def get_plugin_path(environment, plugin_name): return None -def get_reference_paths(environment): +def get_reference_paths(): """Helper method returning a tuple with the server and the local paths. - The dictionary environment contains the keys request, response, - session, plugins, .... - """ - request = environment['request'] - - server_path = os.path.join('applications', request.application) - client_path = os.path.join(os.path.sep, request.application) + server_path = os.path.join('applications', current.request.application) + client_path = os.path.join(os.path.sep, current.request.application) return (server_path, client_path) @@ -218,38 +208,35 @@ def get_set_field(field): return [] -def get_script_path(environment): +def get_script_path(script_path): """Helper method returning the local path of the main script. the local path is defined with respect to the application directory. - The dictionary environment contains the keys request, response, - session, plugins, .... + The default script is static/plugin_dbui/main.js - The script name can be set via the url. + The script name can be set via the url using the argument script + It is search in script_path, i.e static/scripts """ - request = environment['request'] - # default path - base = os.path.join(os.path.sep, request.application) + base = os.path.join(os.path.sep, current.request.application) script = os.path.join(base, 'static', 'plugin_dbui', 'main.js') # if the user specified a script in the URL - if "script" in request.vars: - script = request.vars.script + if "script" in current.request.vars: + script = current.request.vars.script if not script.endswith(".js"): script = '%s.js' % script - plugins = environment['plugins'] - server_path = os.path.join('applications', request.application) - script_dir = os.path.join(server_path, plugins.dbui.script_path) + server_path = os.path.join('applications', current.request.application) + script_dir = os.path.join(server_path, script_path) if script not in os.listdir(script_dir): raise HTTP(500, 'Request script "%s" does not exist !!!' % script) # return 'Request script "%s" does not exist !!!' % script - script = os.path.join(base, plugins.dbui.script_path, script) + script = os.path.join(base, script_path, script) return script @@ -287,6 +274,13 @@ def is_foreign_field(field): return field.type.startswith("reference") +def is_mathjax(): + """Helper function returning true is the mathjax plugin is installed. + + """ + return get_plugin_path('plugin_mathjax') != None + + def is_set_field(field): """Helper function returning true if the gluon.dal.field value should be in a set of values. diff --git a/modules/plugin_dbui/navtree.py b/modules/plugin_dbui/navtree.py index 62e2b773..67135d0d 100644 --- a/modules/plugin_dbui/navtree.py +++ b/modules/plugin_dbui/navtree.py @@ -6,6 +6,7 @@ __version__ = "$Revision$" import locale from gluon import current +from helper import is_mathjax def cfg_configurable_url_panel(key, value): @@ -32,10 +33,15 @@ def cfg_configurable_url_panel(key, value): 'selectorCfg':None, 'xtype': 'xpanelwithurlselector'} - cfg['panelCfg'] = {'plugins': ['pPanelMathJax'], + # configuration of the main panel displaying url + cfg['panelCfg'] = {'plugins': [], 'preventBodyReset': True, 'xtype': 'panel'} + if is_mathjax: + cfg['panelCfg']['plugins'].append('pPanelMathJax') + + # configuration of the selector cfg['selectorCfg'] = {'defaults': {'anchor': '99%'}, 'items': cfg_form_items, 'title': 'Configure', @@ -56,9 +62,12 @@ def cfg_url_panel(key, url): """ cfg = {'autoLoad': url, - 'plugins': ['pPanelMathJax'], + 'plugins': [], 'preventBodyReset': True, 'xtype': 'panel'} + + if is_mathjax: + cfg['plugins'].append('pPanelMathJax') return cfg -- GitLab