add mandatory title and name args to plugin creation, remove title()
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 20 Dec 2012 14:33:47 +0000 (15:33 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 20 Dec 2012 14:33:47 +0000 (15:33 +0100)
as a method

engine/composite.py
engine/plugin.py
engine/views.py
plugins/simplelist.py
plugins/slicelist.py
plugins/tabs.py
plugins/verticallayout.py

index ec2a678..fd72db5 100644 (file)
@@ -14,7 +14,7 @@ class Composite (Plugin):
         # {% for son in sons %} {{ son.rendered }} ...
         return { 'sons': 
                  [ { 'rendered': son.render(request),
-                     'title': son.title(),
+                     'title': son.title,
                      'uuid': son.uuid}
                    for son in self.sons ]}
 
index 832f7cd..2645810 100644 (file)
@@ -20,29 +20,58 @@ class Plugin:
     # using a simple incremental scheme to generate uuids for now
     uuid=0
 
+    # xxx should generate some random id
     @staticmethod
     def newuuid():
         Plugin.uuid += 1
         return Plugin.uuid
 
-    def __init__ (self, visible=True, hidable=True, hidden_by_default=False, **settings):
-        # xxx should generate some random id
+    ########## 
+    # Constructor
+    #### mandatory
+    # . title: is used visually for displaying the widget
+    # . name:  a simple id suitable for forging css names
+    #### optional
+    # . hidable: whether it can be turned on and off from the UI
+    #   like e.g. PleKitToggle
+    # . hidden_by_default: if hidable, what's the initial status
+    # . visible: if not set the plugin does not show up at all,
+    #   not quite sure what this was for
+    #### internal data
+    # . uuid: created internally
+    # . rank: this is for plugins sons of a composite plugin
+    #### custom
+    # any other setting can also be set when creating the object, like
+    # p=Plugin(foo='bar')
+    # which will result in 'foo' being accessible to the template engine
+    # 
+    def __init__ (self, title, name,
+                  visible=True, hidable=True, hidden_by_default=False, **settings):
+        # what is in this dictionary will get exposed to template and to javascript
+        self._settings=settings
+        self.title=title
+        self.name=name
+        self.add_to_settings ( ['title','name'] )
         self.uuid=Plugin.newuuid()
         self.visible=visible
         self.hidable=hidable
         self.hidden_by_default=hidden_by_default
+        self.add_to_settings( ['uuid','visible','hidable','hidden_by_default'] )
         # we store as a dictionary the arguments passed to constructor
         # e.g. SimpleList (list=[1,2,3]) => _settings = { 'list':[1,2,3] }
         # our own settings are not made part of _settings but could be..
-        self._settings=settings
         if self.need_debug():
             print "Plugin.__init__ Created plugin with settings %s"%self._settings.keys()
 
     # subclasses might handle some fields in their own way, 
     # in which case this call is needed to capture that setting
     # see e.g. SimpleList or SliceList for an example of that
-    def add_to_settings (self, setting_name):
-        self._settings[setting_name]=getattr(self,setting_name)
+    def add_to_settings (self, setting_name_s):
+        if not isinstance (setting_name_s, list):
+            self._settings[setting_name_s]=getattr(self,setting_name_s)
+        else:
+            for setting_name in setting_name_s:
+                self._settings[setting_name]=getattr(self,setting_name)
 
     def classname (self): 
         try:    return self.__class__.__name__
@@ -155,8 +184,6 @@ class Plugin:
             method(self,request,v)
 
     ######################################## abstract interface
-    def title (self): return "you should redefine title()"
-
     # your plugin is expected to implement either 
     # (*) def render_content(self, request) -> html fragment
     # -- or --
index 7758ac6..f2c157f 100644 (file)
@@ -20,25 +20,32 @@ def test_plugin_view (request):
     template_env = {}
     
     main_plugin = \
-        VerticalLayout ( sons = [ SimpleList (list=hard_wired_list, 
+        VerticalLayout ( title='title for the vertical layout',name='vertical1',
+        sons = [ SimpleList (title='SimpleList and dataTables',
+                                              name='simplelist1',
+                                              list=hard_wired_list, 
                                               header='Hard wired', 
                                               foo='the value for foo',
                                               with_datatables=True),
-                                  Tabs (sons = [ Raw (html= 3*lorem_p),
-                                                 SliceList(list=hard_wired_slice_names),
-                                                 Raw (html=lorem) ]),
-                                  SimpleList (list=hard_wired_slice_names,
-                                              headers='Slices in main content') ] )
+                                  Tabs (title='Sample Tabs',name='tabs1',
+                                        sons = [ Raw (title='a raw plugin',name='raw1',
+                                                      html= 3*lorem_p),
+                                                 SliceList(title='a slice list',name='slicelist-main',
+                                                           list=hard_wired_slice_names),
+                                                 Raw (title='raw title',name='raw2',html=lorem) ]),
+                                  SimpleList (title='SimpleList with slice names', 
+                                              name='simplelist2',
+                                              list=hard_wired_slice_names,
+                                              ) ] )
     # define 'content_main' to the template engine
     template_env [ 'content_main' ] = main_plugin.render(request)
 
     ##########
     # lacks a/href to /slice/%s
-    related_plugin = SliceList (visible=True, 
-                                hidable=True,
+    related_plugin = SliceList (title='SliceList plugin',name='slicelist1',
                                 with_datatables='yes', 
                                 list=hard_wired_slice_names, 
-                                header='Slices' )
+                                header='Slices')
     # likewise but on the side view
     template_env [ 'content_related' ] = related_plugin.render (request)
 
index c16c7ea..f119d76 100644 (file)
@@ -13,8 +13,6 @@ class SimpleList (Plugin) :
         self.add_to_settings ('with_datatables')
 
     # SimpleList is useless per se anyways
-    def title (self) : return "Title for Simple List"
-
     def template_file (self): return "simplelist.html"
 
     def requirements (self):
index ac8fc25..1f622aa 100644 (file)
@@ -7,9 +7,6 @@ class SliceList (SimpleList):
         self.list = [ "<a href='/slice/%s/' class='slicelist'>%s</a>"%(x,x) for x in list ]
         self.add_to_settings ('list')
 
-    def title (self):
-        return "Slice list"
-
 #    def requirements (self):
 #        reqs=SimpleList.requirements(self)
 #        reqs['js_files'].append('slice.js')
index b4ad0c0..c91f4cf 100644 (file)
@@ -2,9 +2,6 @@ from engine.composite import Composite
 
 class Tabs (Composite):
     
-    def title (self): 
-        return "Some tabs"
-
     def requirements (self):
         return { 'js_files'     : 'bootstrap/js/bootstrap.js',
                  'css_files'    : ['bootstrap/css/bootstrap.css',
index f109899..9ac6f49 100644 (file)
@@ -4,6 +4,4 @@ from engine.composite import Composite
 
 class VerticalLayout (Composite) :
     
-    def title (self) : return "VLayout title"
-
     def template_file (self):        return "verticallayout.html"