From 058958cdd4f1d5f2f5da50e8dd988c5e623f41d8 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 11 Mar 2013 15:54:45 +0100 Subject: [PATCH] use SliceList rather than SimpleList --- engine/plugin.py | 11 +++++++++-- engine/templates/plugin-setenv.js | 2 +- plugins/simplelist.py | 5 +++-- plugins/slicelist.py | 19 +++++++------------ plugins/static/js/simplelist.js | 1 + trash/dashboard.py | 11 ++++++----- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/engine/plugin.py b/engine/plugin.py index 00b37b7c..92bbe6c9 100644 --- a/engine/plugin.py +++ b/engine/plugin.py @@ -61,7 +61,8 @@ class Plugin: self.title=title if not domid: domid=Plugin.newdomid() self.domid=domid - self.classname=self._classname() + self.classname=self._py_classname() + self.plugin_classname=self._js_classname() self.visible=visible self.togglable=togglable self.toggled=toggled @@ -77,10 +78,14 @@ class Plugin: # do this only once the structure is fine self.pluginset.record_plugin(self) - def _classname (self): + def _py_classname (self): try: return self.__class__.__name__ except: return 'Plugin' + def _js_classname (self): + try: return self.plugin_classname () + except: return self._py_classname() + ########## def need_debug (self): if not DEBUG: return False @@ -221,3 +226,5 @@ class Plugin: # also 'query_uuid' gets replaced with query.uuid def json_settings_list (self): return ['json_settings_list-must-be-redefined'] + # might also define this one; see e.g. slicelist.py that piggybacks simplelist js code + # def plugin_classname (self): diff --git a/engine/templates/plugin-setenv.js b/engine/templates/plugin-setenv.js index f6c27faa..0d44075b 100644 --- a/engine/templates/plugin-setenv.js +++ b/engine/templates/plugin-setenv.js @@ -1 +1 @@ -$(document).ready(function() { jQuery('#{{ domid }}').{{ classname }}({{ settings_json|safe }}); }); +$(document).ready(function() { jQuery('#{{ domid }}').{{ plugin_classname }}({{ settings_json|safe }}); }); diff --git a/plugins/simplelist.py b/plugins/simplelist.py index d4cefb1c..371e5d6c 100644 --- a/plugins/simplelist.py +++ b/plugins/simplelist.py @@ -3,9 +3,10 @@ from engine.plugin import Plugin class SimpleList (Plugin) : # only deal with our own stuff here and let Plugin handle the rest - def __init__ (self, list=[], with_datatables=False, **settings): + def __init__ (self, key, value, with_datatables=False, **settings): Plugin.__init__ (self, **settings) - self.list=list + self.key=key + self.value=value self.with_datatables = with_datatables # SimpleList is useless per se anyways diff --git a/plugins/slicelist.py b/plugins/slicelist.py index c9804234..92673f26 100644 --- a/plugins/slicelist.py +++ b/plugins/slicelist.py @@ -1,17 +1,12 @@ from plugins.simplelist import SimpleList +# the SimpleList plugin requires 'key' and 'value' that are used +# on the results of the query for rendering class SliceList (SimpleList): - def __init__ (self, list=[], **settings): - SimpleList.__init__(self, **settings) - self.list = [ "%s"%(x,x) for x in list ] + def __init__ (self, **settings): + SimpleList.__init__(self, key='slice_hrn', value='slice_hrn', **settings) -# def requirements (self): -# reqs=SimpleList.requirements(self) -# reqs['js_files'].append('slice.js') -# reqs['js_files'].append('slice2.js') -# reqs['css_files'].append('slice.css') -# reqs['css_files'].append('slice2.css') -# reqs['js_chunks']=['js chunk1','js chunk2'] -# reqs['css_chunks']=['css chunk1','css chunk2'] -# return reqs + # writing a js plugin for that would be overkill, just use SimpleList + def plugin_classname (self): + return 'SimpleList' diff --git a/plugins/static/js/simplelist.js b/plugins/static/js/simplelist.js index 120c6f96..c49456b0 100644 --- a/plugins/static/js/simplelist.js +++ b/plugins/static/js/simplelist.js @@ -64,6 +64,7 @@ simplelist_debug=false; } var options = e.data.data().SimpleList.options; var is_cached = options.query.timestamp != 'now' ? true : false; + // here is where we use 'key' and 'value' from the SimpleList (python) constructor html_code=myslice_html_ul(rows, options.key, options.value, is_cached)+"
"; e.data.html(html_code); var $elt = e.data; diff --git a/trash/dashboard.py b/trash/dashboard.py index 35eeb336..8dc2dbe9 100644 --- a/trash/dashboard.py +++ b/trash/dashboard.py @@ -10,7 +10,7 @@ from django.contrib.auth.decorators import login_required from engine.pluginset import PluginSet from engine.manifoldquery import ManifoldQuery -from plugins.simplelist import SimpleList +from plugins.slicelist import SliceList # from myslice.viewutils import topmenu_items, the_user @@ -28,19 +28,20 @@ def dashboard_view (request): # xxx filter : should filter on the slices the logged user can see # we don't have the user's hrn yet # in addition this currently returns all slices anyways + # filter = ... sort='slice_hrn',) pluginset.enqueue_query (slices_query) - main_plugin = SimpleList ( # setting visible attributes first + main_plugin = SliceList ( # setting visible attributes first pluginset=pluginset, - title='Asynchroneous SimpleList', + title='Asynchroneous SliceList', header='slices list', with_datatables=True, toggled=True, # this is required for the javascript code query=slices_query, - key='slice_hrn', - value='slice_hrn', +# key='slice_hrn', +# value='slice_hrn', ) # variables that will get passed to the view-plugin.html template -- 2.43.0