Skip to content
Snippets Groups Projects
Commit 8308e22b authored by Renaud Le Gac's avatar Renaud Le Gac
Browse files

Add the plugin parameter with_grid_filter.

parent 55c4c205
No related branches found
No related tags found
No related merge requests found
""" plugin_dbui.py """ plugin_dbui.py
Controllers expose by the plugin: Controllers expose by the plugin:
index index
database database
configuration configuration
Author: R. Le Gac Author: R. Le Gac
$Id$ $Id$
""" """
...@@ -25,16 +25,16 @@ from pprint import pprint ...@@ -25,16 +25,16 @@ from pprint import pprint
def index(): def index():
""" Main Controller to run the plugin """ Main Controller to run the plugin
SYNOPSIS SYNOPSIS
http://localhost:8000/application/plugin_dbui[?options] http://localhost:8000/application/plugin_dbui[?options]
DESCRIPTION DESCRIPTION
Main controller to launch the plugin. Main controller to launch the plugin.
Load the extjs librairy and the associated css files. Load the extjs librairy and the associated css files.
Load the javascript librairy for the plugin. Load the javascript librairy for the plugin.
Define view. Define view.
PARAMETERS WHICH CAN BE SET VIA THE PLUGINMANAGER PARAMETERS WHICH CAN BE SET VIA THE PLUGINMANAGER
...@@ -45,221 +45,226 @@ def index(): ...@@ -45,221 +45,226 @@ def index():
script_path script_path
The relative path where scripts are located. The relative path where scripts are located.
By default static/plugin_dbui/scripts By default static/plugin_dbui/scripts
with_grid_filter
Add the javascript librairy for gridFilter
OPTIONS OPTIONS
debug debug
activate the debug mode on the server side. activate the debug mode on the server side.
script foo script foo
run the javascript foo in the framework defined by the plugin. run the javascript foo in the framework defined by the plugin.
The scripts are stored in the directory application/static/script The scripts are stored in the directory application/static/script
by default the javascript main.js is launch. by default the javascript main.js is launch.
EXAMPLES EXAMPLES
http://localhost:8000/application/plugin_dbui http://localhost:8000/application/plugin_dbui
http://localhost:8000/application/plugin_dbui?debug http://localhost:8000/application/plugin_dbui?debug
http://localhost:8000/application/plugin_dbui?script=foo&debug http://localhost:8000/application/plugin_dbui?script=foo&debug
""" """
# define plugin parameters and their default value # define plugin parameters and their default value
plugins = PluginManager('dbui', plugins = PluginManager('dbui',
page_view='plugin_dbui.html', page_view='plugin_dbui.html',
script_path='static/plugin_dbui/scripts') script_path='static/plugin_dbui/scripts',
with_grid_filter=False)
# paths
base = os.path.join(os.path.sep, request.application) # paths
appjs = os.path.join(base, 'static', 'plugin_dbui', 'lib') base = os.path.join(os.path.sep, request.application)
extjs = os.path.join(base, 'static', 'plugin_extjs') appjs = os.path.join(base, 'static', 'plugin_dbui', 'lib')
server_path = os.path.join('applications', request.application) extjs = os.path.join(base, 'static', 'plugin_extjs')
script_path = os.path.join(server_path, plugins.dbui.script_path) server_path = os.path.join('applications', request.application)
script_path = os.path.join(server_path, plugins.dbui.script_path)
# check the presence of the extjs plugin
path = os.path.join(server_path, 'static', 'plugin_extjs') # check the presence of the extjs plugin
if not os.path.exists(path): path = os.path.join(server_path, 'static', 'plugin_extjs')
raise HTTP(500, 'The plugin extjs is not install !') if not os.path.exists(path):
raise HTTP(500, 'The plugin extjs is not install !')
# option debug
debug = False # option debug
if "debug" in request.get_vars: debug = False
debug = True if "debug" in request.get_vars:
debug = True
# option script
script = "default" # option script
if "script" in request.get_vars: script = "default"
script = request.get_vars.script if "script" in request.get_vars:
script = request.get_vars.script
if not script.endswith(".js"):
script = '%s.js' % script if not script.endswith(".js"):
script = '%s.js' % script
if script not in os.listdir(script_path):
return 'Request script "%s" does not exist !!!' % script if script not in os.listdir(script_path):
return 'Request script "%s" does not exist !!!' % script
# css files
csslibs = [os.path.join(extjs, 'resources', 'css', 'ext-all.css'), # css files
os.path.join(extjs, 'examples', 'shared', 'icons', 'silk.css'), csslibs = [os.path.join(extjs, 'resources', 'css', 'ext-all.css'),
os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'css', 'GridFilters.css'), os.path.join(extjs, 'examples', 'shared', 'icons', 'silk.css')]
os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'css', 'RangeMenu.css'),
# os.path.join(extjs, 'examples', 'shared', 'examples.css'), if plugins.dbui.with_grid_filter:
] cpath = os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'css')
csslibs.extend([os.path.join(cpath, 'GridFilters.css'),
# javascript libraries os.path.join(cpath, 'RangeMenu.css')])
if debug:
jslibs = [os.path.join(extjs, 'adapter', 'ext', 'ext-base-debug.js'), # javascript libraries
os.path.join(extjs, 'ext-all-debug.js'), if debug:
# os.path.joinextjs, 'examples', 'ux', 'ux-all-debug.js'), jslibs = [os.path.join(extjs, 'adapter', 'ext', 'ext-base-debug.js'),
] os.path.join(extjs, 'ext-all-debug.js')]
else:
jslibs = [os.path.join(extjs, 'adapter', 'ext', 'ext-base.js'), else:
os.path.join(extjs, 'ext-all.js'), jslibs = [os.path.join(extjs, 'adapter', 'ext', 'ext-base.js'),
os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'menu', 'RangeMenu.js'), os.path.join(extjs, 'ext-all.js')]
os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'menu', 'ListMenu.js'),
if plugins.dbui.with_grid_filter:
os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'GridFilters.js'), jpath = os.path.join(extjs, 'examples', 'ux', 'gridfilters')
os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'filter', 'Filter.js'), li = [os.path.join(jpath, 'menu', 'RangeMenu.js'),
os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'filter', 'BooleanFilter.js'), os.path.join(jpath, 'menu', 'ListMenu.js'),
os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'filter', 'DateFilter.js'), os.path.join(jpath, 'GridFilters.js'),
os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'filter', 'ListFilter.js'), os.path.join(jpath, 'filter', 'Filter.js'),
os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'filter', 'NumericFilter.js'), os.path.join(jpath, 'filter', 'BooleanFilter.js'),
os.path.join(extjs, 'examples', 'ux', 'gridfilters', 'filter', 'StringFilter.js'), os.path.join(jpath, 'filter', 'DateFilter.js'),
# os.path.join(extjs, 'examples', 'shared', 'examples.js'), os.path.join(jpath, 'filter', 'ListFilter.js'),
] os.path.join(jpath, 'filter', 'NumericFilter.js'),
os.path.join(jpath, 'filter', 'StringFilter.js')]
# plugin javascript libraries jslib.extend(li)
applibs = []
for file in os.listdir(os.path.join(server_path, 'static', 'plugin_dbui', 'lib')): # plugin libraries
if file.endswith(".js"): applibs = []
applibs.append(os.path.join(appjs, file)) for file in os.listdir(os.path.join(server_path, 'static', 'plugin_dbui', 'lib')):
if file.endswith(".js"):
# main application script applibs.append(os.path.join(appjs, file))
applibs.sort()
applibs.append(os.path.join(base, plugins.dbui.script_path, script)) # main application script
applibs.sort()
# page view applibs.append(os.path.join(base, plugins.dbui.script_path, script))
response.view = plugins.dbui.page_view
# page view
return dict(clibs=csslibs,\ response.view = plugins.dbui.page_view
jlibs=jslibs,\
alibs= applibs,\ return dict(clibs=csslibs,\
appdebug=debug,\ jlibs=jslibs,\
cfgSvcMethods=cfgSvc._getMethods()) alibs= applibs,\
appdebug=debug,\
cfgSvcMethods=cfgSvc._getMethods())
def database(): def database():
""" Controllers to perform operation on the database. """ Controllers to perform operation on the database.
Act as a bridge between the web browser and the database service. Act as a bridge between the web browser and the database service.
All information defining the operation are sent via the POST/GET methods. All information defining the operation are sent via the POST/GET methods.
It contains steering keyword defining the requested action. It contains steering keyword defining the requested action.
Return a JSON string when the action is successful. Return a JSON string when the action is successful.
Otherwise return and HTTP error Otherwise return and HTTP error
""" """
debug = "debug" in request.vars and (request.vars.debug == 'true') debug = "debug" in request.vars and (request.vars.debug == 'true')
if debug: if debug:
print "\nSTART DATABASE CONTROLLER" print "\nSTART DATABASE CONTROLLER"
print "Method:", request.env.request_method print "Method:", request.env.request_method
print "Arguments:", request.vars print "Arguments:", request.vars
try: try:
# decode the data dictionary # decode the data dictionary
if "data" in request.vars and isinstance(request.vars.data, str): if "data" in request.vars and isinstance(request.vars.data, str):
request.vars.data = json.loads(request.vars.data) request.vars.data = json.loads(request.vars.data)
di = dbSvc.proceed(request.vars) di = dbSvc.proceed(request.vars)
resp = json.dumps(di) resp = json.dumps(di)
except BaseException, e: except BaseException, e:
print "Exception in the database controller:" print "Exception in the database controller:"
print "-"*72 print "-"*72
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
print "-"*72 print "-"*72
raise HTTP(500, e) raise HTTP(500, e)
if debug: if debug:
print "\nDATABASE CONTROLLER RESPONSE IS:" print "\nDATABASE CONTROLLER RESPONSE IS:"
pprint(di) pprint(di)
print "END OF DATABASE CONTROLLER\n" print "END OF DATABASE CONTROLLER\n"
return resp return resp
def configuration(): def configuration():
""" Controllers/router for the web service cfgSVc """ Controllers/router for the web service cfgSVc
Act as a bridge between the web browser and the configuration service. Act as a bridge between the web browser and the configuration service.
Relies on Ext.Direct see specification: Relies on Ext.Direct see specification:
http://www.extjs.com/products/extjs/direct.php http://www.extjs.com/products/extjs/direct.php
Act as a router for the cfgSvc service (see Ext.Direct Extjs 3.1.1) Act as a router for the cfgSvc service (see Ext.Direct Extjs 3.1.1)
Decode the raw HTTP post request: Decode the raw HTTP post request:
{action: "cfgSvc", method: x, data: y, tip: i, type: "rpc"} {action: "cfgSvc", method: x, data: y, tip: i, type: "rpc"}
Return a JSON string with the result of the request: Return a JSON string with the result of the request:
{action: "cfgSvc", method: x, result: y, tip: i, type: "rpc"} {action: "cfgSvc", method: x, result: y, tip: i, type: "rpc"}
Otherwise return and HTTP error. Otherwise return and HTTP error.
For more detail on Ext.Direct see specification: For more detail on Ext.Direct see specification:
http://www.extjs.com/products/extjs/direct.php http://www.extjs.com/products/extjs/direct.php
""" """
debug = "debug" in request.vars and (request.vars.debug == 'true') debug = "debug" in request.vars and (request.vars.debug == 'true')
# NOTE: the server cfgSvc is start at the beginning # NOTE: the server cfgSvc is start at the beginning
# when building the model (db.py) # when building the model (db.py)
# decode the raw HTTP post # decode the raw HTTP post
# ExtJs.3.1.1 {action: "xx", method: "y", data: [], type:"rpc", tid:2} # ExtJs.3.1.1 {action: "xx", method: "y", data: [], type:"rpc", tid:2}
req = json.loads(request.body.read()) req = json.loads(request.body.read())
if debug: if debug:
print "\nSTART CONFIGURATION CONTROLLER:" print "\nSTART CONFIGURATION CONTROLLER:"
pprint(req) pprint(req)
# receive a list of dictionary for a multi-request # receive a list of dictionary for a multi-request
li = [] li = []
if isinstance(req, list): if isinstance(req, list):
li.extend(req) li.extend(req)
else: else:
li.append(req) li.append(req)
for di in li: for di in li:
# construct the command to be executed # construct the command to be executed
args = di["data"] args = di["data"]
cmd = "%s.%s(*args)" % (di["action"], di["method"]) cmd = "%s.%s(*args)" % (di["action"], di["method"])
if args == None: if args == None:
cmd = "%s.%s()" % (di["action"], di["method"]) cmd = "%s.%s()" % (di["action"], di["method"])
# execute the command and return HTTP exception # execute the command and return HTTP exception
# when an internal error occurred # when an internal error occurred
try: try:
res = eval(cmd) res = eval(cmd)
except BaseException, e: except BaseException, e:
print "Exception in the configuration controller:" print "Exception in the configuration controller:"
print "-"*72 print "-"*72
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
print "-"*72 print "-"*72
raise HTTP(500, e) raise HTTP(500, e)
# NOTE: the client expect the following object: # NOTE: the client expect the following object:
# ExtJs.3.1.1 {action: "xx", method: "y", result: [], type:"rpc", tid:2} # ExtJs.3.1.1 {action: "xx", method: "y", result: [], type:"rpc", tid:2}
del di["data"] del di["data"]
di["result"] = res di["result"] = res
if debug: if debug:
print "\nCONFIGURATION CONTROLLER RESPONSE IS:" print "\nCONFIGURATION CONTROLLER RESPONSE IS:"
pprint(li) pprint(li)
print "\nEND OF CONFIGURATION CONTROLLER\n" print "\nEND OF CONFIGURATION CONTROLLER\n"
# encode the data as a json string # encode the data as a json string
return json.dumps(li) return json.dumps(li)
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment