From c86f4d109aa25eddb364f190ae0324a95f7eac90 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 23 Sep 2013 14:56:29 +0200 Subject: [PATCH] uniform plugin layout with code in __init__.py --- plugins/messages/__init__.py | 45 ++++++++++++++++++++++++++++++ plugins/messages/messages.py | 45 ------------------------------ plugins/querycode/__init__.py | 30 ++++++++++++++++++++ plugins/querycode/querycode.py | 30 -------------------- plugins/quickfilter/__init__.py | 23 +++++++++++++++ plugins/quickfilter/quickfilter.py | 23 --------------- plugins/raw/__init__.py | 12 ++++++++ plugins/raw/raw.py | 12 -------- plugins/stack/__init__.py | 11 ++++++++ plugins/stack/stack.py | 11 -------- plugins/tabs/__init__.py | 19 +++++++++++++ plugins/tabs/tabs.py | 19 ------------- portal/sliceview.py | 13 ++++----- trash/dashboard.py | 6 ++-- trash/pluginview.py | 12 ++++---- 15 files changed, 155 insertions(+), 156 deletions(-) delete mode 100644 plugins/messages/messages.py delete mode 100644 plugins/querycode/querycode.py delete mode 100644 plugins/quickfilter/quickfilter.py delete mode 100644 plugins/raw/raw.py delete mode 100644 plugins/stack/stack.py delete mode 100644 plugins/tabs/tabs.py diff --git a/plugins/messages/__init__.py b/plugins/messages/__init__.py index e69de29b..65baea15 100644 --- a/plugins/messages/__init__.py +++ b/plugins/messages/__init__.py @@ -0,0 +1,45 @@ +from unfold.plugin import Plugin + +# lists levels and sets them to enabled or not at startup +default_levels = {'fatal': True, 'error': True, 'warning' : True, 'info' : True, 'debug' : False} + +# there are two implementations available here +# one shows up in the main page like a regular part of the page, +# while the other one relies on transient popups +# by default we use the latter, but you can specify +# transient=False if you want to use the former +# xxx +# also the pieces that go with this transient mode are +# under views/templates, it would make sense to move them over here +# however it turns out that views/templates/base.html unconditionnally +# includes messages-transient-header.html +class Messages (Plugin): + + def __init__ (self, transient=True, levels=None, **settings): + Plugin.__init__ (self, **settings) + if levels is None: levels=default_levels + # shortcut: 'ALL' turn everything on + elif levels=='ALL': levels=dict( [ (k,True) for k in default_levels ] ) + elif levels=='NONE': levels=dict( [ (k,False) for k in default_levels ] ) + self.transient=transient + self.levels=levels + + def template_file (self): + return "messages.html" if not self.transient else "messages-transient.html" + + def requirements (self): + return { + 'js_files' : [ "js/messages.js", "js/manifold.js", ], + 'css_files' : "css/messages.css", + } + + # although this has no query, we need a plugin instance to be created in the js output + def export_json_settings (self): + return True + # the js plugin expects a domid + def json_settings_list (self): + return [ 'plugin_uuid', 'levels' ] + + # and we don't need a spin wheel + def start_with_spin (self): + return False diff --git a/plugins/messages/messages.py b/plugins/messages/messages.py deleted file mode 100644 index 65baea15..00000000 --- a/plugins/messages/messages.py +++ /dev/null @@ -1,45 +0,0 @@ -from unfold.plugin import Plugin - -# lists levels and sets them to enabled or not at startup -default_levels = {'fatal': True, 'error': True, 'warning' : True, 'info' : True, 'debug' : False} - -# there are two implementations available here -# one shows up in the main page like a regular part of the page, -# while the other one relies on transient popups -# by default we use the latter, but you can specify -# transient=False if you want to use the former -# xxx -# also the pieces that go with this transient mode are -# under views/templates, it would make sense to move them over here -# however it turns out that views/templates/base.html unconditionnally -# includes messages-transient-header.html -class Messages (Plugin): - - def __init__ (self, transient=True, levels=None, **settings): - Plugin.__init__ (self, **settings) - if levels is None: levels=default_levels - # shortcut: 'ALL' turn everything on - elif levels=='ALL': levels=dict( [ (k,True) for k in default_levels ] ) - elif levels=='NONE': levels=dict( [ (k,False) for k in default_levels ] ) - self.transient=transient - self.levels=levels - - def template_file (self): - return "messages.html" if not self.transient else "messages-transient.html" - - def requirements (self): - return { - 'js_files' : [ "js/messages.js", "js/manifold.js", ], - 'css_files' : "css/messages.css", - } - - # although this has no query, we need a plugin instance to be created in the js output - def export_json_settings (self): - return True - # the js plugin expects a domid - def json_settings_list (self): - return [ 'plugin_uuid', 'levels' ] - - # and we don't need a spin wheel - def start_with_spin (self): - return False diff --git a/plugins/querycode/__init__.py b/plugins/querycode/__init__.py index e69de29b..55da3e9c 100644 --- a/plugins/querycode/__init__.py +++ b/plugins/querycode/__init__.py @@ -0,0 +1,30 @@ +from unfold.plugin import Plugin + +class QueryCode (Plugin): + + def __init__ (self, query, **settings): + Plugin.__init__ (self, **settings) + self.query=query + + def template_file (self): + return "querycode.html" + + def requirements (self): + return { + 'js_files' : [ + "js/querycode.js", + "js/manifold.js", "js/manifold-query.js", + "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js", + "js/shAutoloader.js","js/shCore.js","js/shBrushPython.js","js/shBrushRuby.js", + ] , +# thierry: see this file for details of why we turn this off for now + 'css_files': [ + "css/querycode.css" , + "css/shCore.css","css/shCoreDefault.css","css/shThemeDefault.css", + ], + } + + def json_settings_list (self): return ['plugin_uuid','query_uuid'] + + # because we have a link to a query it looks like we need a spin, let's make this right + def start_with_spin (self): return False diff --git a/plugins/querycode/querycode.py b/plugins/querycode/querycode.py deleted file mode 100644 index 55da3e9c..00000000 --- a/plugins/querycode/querycode.py +++ /dev/null @@ -1,30 +0,0 @@ -from unfold.plugin import Plugin - -class QueryCode (Plugin): - - def __init__ (self, query, **settings): - Plugin.__init__ (self, **settings) - self.query=query - - def template_file (self): - return "querycode.html" - - def requirements (self): - return { - 'js_files' : [ - "js/querycode.js", - "js/manifold.js", "js/manifold-query.js", - "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js", - "js/shAutoloader.js","js/shCore.js","js/shBrushPython.js","js/shBrushRuby.js", - ] , -# thierry: see this file for details of why we turn this off for now - 'css_files': [ - "css/querycode.css" , - "css/shCore.css","css/shCoreDefault.css","css/shThemeDefault.css", - ], - } - - def json_settings_list (self): return ['plugin_uuid','query_uuid'] - - # because we have a link to a query it looks like we need a spin, let's make this right - def start_with_spin (self): return False diff --git a/plugins/quickfilter/__init__.py b/plugins/quickfilter/__init__.py index e69de29b..9ac95ae1 100644 --- a/plugins/quickfilter/__init__.py +++ b/plugins/quickfilter/__init__.py @@ -0,0 +1,23 @@ +from unfold.plugin import Plugin + +class QuickFilter (Plugin) : + + def __init__ (self, criterias, **settings): + Plugin.__init__ (self, **settings) + self.criterias=criterias + self.page.expose_js_metadata() + + def template_file (self): return "quickfilter.html" + + def requirements (self): + return { + 'js_files' : [ "js/quickfilter.js", "js/metadata.js", + ], + 'css_files': "css/quickfilter.css", + } + + def json_settings_list (self): + return ['criterias','plugin_uuid'] + + def template_env (self,request): + return {'criterias':self.criterias} diff --git a/plugins/quickfilter/quickfilter.py b/plugins/quickfilter/quickfilter.py deleted file mode 100644 index 9ac95ae1..00000000 --- a/plugins/quickfilter/quickfilter.py +++ /dev/null @@ -1,23 +0,0 @@ -from unfold.plugin import Plugin - -class QuickFilter (Plugin) : - - def __init__ (self, criterias, **settings): - Plugin.__init__ (self, **settings) - self.criterias=criterias - self.page.expose_js_metadata() - - def template_file (self): return "quickfilter.html" - - def requirements (self): - return { - 'js_files' : [ "js/quickfilter.js", "js/metadata.js", - ], - 'css_files': "css/quickfilter.css", - } - - def json_settings_list (self): - return ['criterias','plugin_uuid'] - - def template_env (self,request): - return {'criterias':self.criterias} diff --git a/plugins/raw/__init__.py b/plugins/raw/__init__.py index e69de29b..01f59e9f 100644 --- a/plugins/raw/__init__.py +++ b/plugins/raw/__init__.py @@ -0,0 +1,12 @@ +from unfold.plugin import Plugin + +# usage Raw (html="some html text") + +class Raw (Plugin): + + def __init__ (self, html, **kwds): + Plugin.__init__ (self, **kwds) + self.html=html + + def render_content (self, request): + return self.html diff --git a/plugins/raw/raw.py b/plugins/raw/raw.py deleted file mode 100644 index 01f59e9f..00000000 --- a/plugins/raw/raw.py +++ /dev/null @@ -1,12 +0,0 @@ -from unfold.plugin import Plugin - -# usage Raw (html="some html text") - -class Raw (Plugin): - - def __init__ (self, html, **kwds): - Plugin.__init__ (self, **kwds) - self.html=html - - def render_content (self, request): - return self.html diff --git a/plugins/stack/__init__.py b/plugins/stack/__init__.py index e69de29b..c8ddbea7 100644 --- a/plugins/stack/__init__.py +++ b/plugins/stack/__init__.py @@ -0,0 +1,11 @@ +from django.template.loader import render_to_string + +from unfold.composite import Composite + +class Stack (Composite) : + + def template_file (self): return "stack.html" + def template_env (self, request): + env = Composite.template_env (self, request) + env['domid'] = self.domid + return env diff --git a/plugins/stack/stack.py b/plugins/stack/stack.py deleted file mode 100644 index c8ddbea7..00000000 --- a/plugins/stack/stack.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.template.loader import render_to_string - -from unfold.composite import Composite - -class Stack (Composite) : - - def template_file (self): return "stack.html" - def template_env (self, request): - env = Composite.template_env (self, request) - env['domid'] = self.domid - return env diff --git a/plugins/tabs/__init__.py b/plugins/tabs/__init__.py index e69de29b..6da94da1 100644 --- a/plugins/tabs/__init__.py +++ b/plugins/tabs/__init__.py @@ -0,0 +1,19 @@ +from unfold.composite import Composite + +class Tabs (Composite): + + def requirements (self): + return { 'js_files' : ['js/tabs.js', 'js/bootstrap.js'], + 'css_files' : ['css/bootstrap.css', 'css/tabs.css', ] + } + + def template_file (self): + return "tabs.html" + + # see Composite.py for the details of template_env, that exposes global + # 'sons' as a list of sons with each a set of a few attributes + def json_settings_list (self): + return [] + + def export_json_settings(self): + return True diff --git a/plugins/tabs/tabs.py b/plugins/tabs/tabs.py deleted file mode 100644 index 6da94da1..00000000 --- a/plugins/tabs/tabs.py +++ /dev/null @@ -1,19 +0,0 @@ -from unfold.composite import Composite - -class Tabs (Composite): - - def requirements (self): - return { 'js_files' : ['js/tabs.js', 'js/bootstrap.js'], - 'css_files' : ['css/bootstrap.css', 'css/tabs.css', ] - } - - def template_file (self): - return "tabs.html" - - # see Composite.py for the details of template_env, that exposes global - # 'sons' as a list of sons with each a set of a few attributes - def json_settings_list (self): - return [] - - def export_json_settings(self): - return True diff --git a/portal/sliceview.py b/portal/sliceview.py index 762e64a2..5e8ddf9b 100644 --- a/portal/sliceview.py +++ b/portal/sliceview.py @@ -8,19 +8,18 @@ from manifold.core.query import Query, AnalyzedQuery from myslice.viewutils import topmenu_items, the_user -from plugins.raw.raw import Raw -from plugins.stack.stack import Stack -from plugins.tabs.tabs import Tabs +from plugins.raw import Raw +from plugins.stack import Stack +from plugins.tabs import Tabs from plugins.hazelnut import Hazelnut from plugins.resources_selected import ResourcesSelected from plugins.googlemap import GoogleMap from plugins.senslabmap.senslabmap import SensLabMap -from plugins.querycode.querycode import QueryCode +from plugins.querycode import QueryCode from plugins.query_editor import QueryEditor from plugins.active_filters import ActiveFilters -from plugins.quickfilter.quickfilter import QuickFilter -from plugins.messages.messages import Messages -#from plugins.updater import Updater +from plugins.quickfilter import QuickFilter +from plugins.messages import Messages tmp_default_slice='ple.upmc.myslicedemo' diff --git a/trash/dashboard.py b/trash/dashboard.py index e996477f..20bc15f7 100644 --- a/trash/dashboard.py +++ b/trash/dashboard.py @@ -11,10 +11,10 @@ from unfold.page import Page from manifold.core.query import Query #from manifold.manifoldquery import ManifoldQuery -from plugins.stack.stack import Stack +from plugins.stack import Stack from plugins.lists.slicelist import SliceList -from plugins.querycode.querycode import QueryCode -from plugins.quickfilter.quickfilter import QuickFilter +from plugins.querycode import QueryCode +from plugins.quickfilter import QuickFilter from trash.trashutils import quickfilter_criterias diff --git a/trash/pluginview.py b/trash/pluginview.py index 5440a149..f6198df3 100644 --- a/trash/pluginview.py +++ b/trash/pluginview.py @@ -10,13 +10,13 @@ from django.contrib.auth.decorators import login_required from unfold.page import Page from manifold.core.query import Query -from plugins.stack.stack import Stack -from plugins.tabs.tabs import Tabs +from plugins.stack import Stack +from plugins.tabs import Tabs from plugins.lists.staticlist import StaticList -from plugins.quickfilter.quickfilter import QuickFilter -from plugins.querycode.querycode import QueryCode -from plugins.raw.raw import Raw -from plugins.messages.messages import Messages +from plugins.quickfilter import QuickFilter +from plugins.querycode import QueryCode +from plugins.raw import Raw +from plugins.messages import Messages from plugins.hazelnut import Hazelnut from plugins.updater import Updater -- 2.43.0