yet another round, with 2 new Plugins Tabs and Raw (from raw html)
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 19 Dec 2012 17:15:07 +0000 (18:15 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 19 Dec 2012 17:15:07 +0000 (18:15 +0100)
engine/plugin.py
engine/prelude.py
engine/static/js/with-datatables.js
engine/views.py
myslice/viewutils.py
plugins/raw.py [new file with mode: 0644]
plugins/tabs.py [new file with mode: 0644]
plugins/templates/tabs.html [new file with mode: 0644]
slice/views.py
templates/layout-myslice.html
templates/view-tab.html

index 3b52c80..1ce5102 100644 (file)
@@ -44,7 +44,7 @@ class Plugin:
         except: return 'Plugin'
 
     # shorthands to inspect _settings
-    def get_setting (self, setting, default):
+    def get_setting (self, setting, default=None):
         if setting not in self._settings: return default
         else:                             return self._settings[setting]
 
index bf5e0a9..b983558 100644 (file)
@@ -7,12 +7,12 @@ class Prelude:
     """A class for collecting dependencies on js/css files or fragments"""
 
     keys=[ 'js_files','css_files','js_chunks', 'css_chunks' ]
-    def __init__ (self):
+    def __init__ (self, js_files=[], css_files=[], js_chunks=[], css_chunks=[]):
         # it's tempting to use sets but sets are not ordered..
-        self.js_files  =[]
-        self.css_files =[]
-        self.js_chunks =[]
-        self.css_chunks=[]
+        self.js_files  = Prelude._normalize(js_files)
+        self.css_files = Prelude._normalize(css_files)
+        self.js_chunks = Prelude._normalize(js_chunks)
+        self.css_chunks= Prelude._normalize(css_chunks)
 
     @staticmethod
     def _normalize (input):
index 6acc764..75e4cc2 100644 (file)
@@ -1,2 +1,2 @@
 /* elements with class 'with-datatables' are set to use datatables */
-$(document).ready(function() {$('.with-datatables').each(function() { window.console.log('here'); $(this).dataTable() } ) } )
+$(document).ready(function() {$('.with-datatables').each(function() { $(this).dataTable() } ) } )
index b67197d..7160944 100644 (file)
@@ -6,59 +6,41 @@ from django.template.loader import render_to_string
 from django.shortcuts import render_to_response
 
 from plugins.verticallayout import VerticalLayout
+from plugins.tabs import Tabs
 from plugins.simplelist import SimpleList
 from plugins.slicelist import SliceList
+from plugins.raw import Raw
 
-from myslice.viewutils import topmenu_items, the_user, hard_wired_slice_names
+from myslice.viewutils import topmenu_items, the_user
+from myslice.viewutils import hard_wired_slice_names, hard_wired_list, lorem_p, lorem
 
 def test_plugin_view (request):
     
     # variables that will get passed to this template
     template_env = {}
     
-    # having html tags right here is not a real use case
-    hard_wired_list=[]
-    hard_wired_list.append("this hard-wired list")
-    hard_wired_list.append("is defined")
-    hard_wired_list.append("in plugins.simplelist.py")
-    hard_wired_list.append("which in turn relies on")
-    hard_wired_list.append("template widget-template.html")
-    hard_wired_list.append("while it should of course")
-    hard_wired_list.append("instead issue a query")
-    hard_wired_list.append("and fill the DOM in js from there")
-    hard_wired_list.append("it would however maybe make sense")
-    hard_wired_list.append("to offer the option to 'datatablify'")
-    hard_wired_list.append("the list from the python code")
-    hard_wired_list.append("just like a standard plugin can be set as visible or not")
-    hard_wired_list.append("")    
-    hard_wired_list.append("OTOH and IMHO, there should be two separate and explicit subclasses of SimpleList for slices or testbeds")
-
-    plugin_main1 = SimpleList (list=hard_wired_list, 
-                               header='Hard wired', 
-                               foo='the value for foo',
-                               with_datatables=True)
-    plugin_main2 = SimpleList (hidable=True, 
-                               list=hard_wired_slice_names,
-                               headers='Slices in main content')
-    layout = VerticalLayout (hidable=True, visible=True,
-                             sons=[plugin_main1, plugin_main2]
-                             )
-#    layout.inspect_request (request,"before first render")
-    content_main = layout.render (request)
-#    layout.inspect_request (request,"after first render")
-    # this will be rendered as the main content - as per view-plugin.html and thus layout-myslice.html
-    template_env [ 'content_main' ] = content_main
+    main_plugin = \
+        VerticalLayout ( sons = [ SimpleList (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') ] )
+    # define 'content_main' to the template engine
+    template_env [ 'content_main' ] = main_plugin.render(request)
 
     ##########
     # lacks a/href to /slice/%s
-    plugin_related = SliceList (visible=True, 
+    related_plugin = SliceList (visible=True, 
                                 hidable=True,
                                 with_datatables='yes', 
                                 list=hard_wired_slice_names, 
                                 header='Slices' )
-    content_related = plugin_related.render (request)
     # likewise but on the side view
-    template_env [ 'content_related' ] = content_related
+    template_env [ 'content_related' ] = related_plugin.render (request)
 
     # more general variables expected in the template
     template_env [ 'title' ] = 'Test Plugin View' 
index 212d310..374417e 100644 (file)
@@ -33,7 +33,27 @@ lorem="""
 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod <code>mazim placerat</code> facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
 """
 
+lorem_p = "<p>"+lorem+"</p>"
+
 hard_wired_slice_names = []
 for site in [ 'inria', 'upmc' , 'ibbt' ]:
     for slice in [ 'foo', 'bar', 'tutu', 'test', 'omf', 'heartbeat' ]:
         hard_wired_slice_names.append ("ple.%s.%s"%(site,slice))
+
+# having html tags right here is not a real use case
+hard_wired_list=[]
+hard_wired_list.append("this hard-wired list")
+hard_wired_list.append("is defined")
+hard_wired_list.append("in plugins.simplelist.py")
+hard_wired_list.append("which in turn relies on")
+hard_wired_list.append("template widget-template.html")
+hard_wired_list.append("while it should of course")
+hard_wired_list.append("instead issue a query")
+hard_wired_list.append("and fill the DOM in js from there")
+hard_wired_list.append("it would however maybe make sense")
+hard_wired_list.append("to offer the option to 'datatablify'")
+hard_wired_list.append("the list from the python code")
+hard_wired_list.append("just like a standard plugin can be set as visible or not")
+hard_wired_list.append("")    
+hard_wired_list.append("OTOH and IMHO, there should be two separate and explicit subclasses of SimpleList for slices or testbeds")
+
diff --git a/plugins/raw.py b/plugins/raw.py
new file mode 100644 (file)
index 0000000..0a0be1d
--- /dev/null
@@ -0,0 +1,8 @@
+from engine.plugin import Plugin
+
+# usage Raw (html="some html text")
+
+class Raw (Plugin):
+
+    def render_content (self, request):
+        return self.get_setting('html')
diff --git a/plugins/tabs.py b/plugins/tabs.py
new file mode 100644 (file)
index 0000000..46e404b
--- /dev/null
@@ -0,0 +1,25 @@
+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' }
+
+    def template (self):
+        return "tabs.html"
+    
+    def render_env (self, request):
+        env = {}
+        sons_rendered = [ son.render(request) for son in self.sons ]
+        sons_titles = [ son.title() for son in self.sons ]
+        ids = range (len(self.sons))
+        # for now we don't have a title to pass
+        sons = [ { 'id':id, 'rendered':rendered, 'title':title } 
+                 for id,rendered,title in zip (ids, sons_rendered, sons_titles) ]
+        env['sons']=sons
+        return env
+    
diff --git a/plugins/templates/tabs.html b/plugins/templates/tabs.html
new file mode 100644 (file)
index 0000000..e8de9eb
--- /dev/null
@@ -0,0 +1,13 @@
+{# could try to set class='active' on the one we want to highlight #}
+<ul class="nav nav-tabs" id='{{ uuid }}'>
+{% for son in sons %}
+<li> <a href="#{{ son.uuid }}" data-toggle="tab"> son.title </a> </li>
+{% endfor %}
+</ul>
+<div class="tab-content">
+{% for son in sons %}
+<div class="tab-pane fade in" id="{{ son.uuid }}">
+{{ son.rendered }}
+</div>
+{% endfor %}
+</div>
index 407e0df..857499a 100644 (file)
@@ -4,6 +4,8 @@ from django.template import RequestContext
 from django.shortcuts import render_to_response
 from django.contrib.auth.decorators import login_required
 
+from engine.prelude import Prelude
+
 from myslice.viewutils import topmenu_items, the_user
 # tmp
 from myslice.viewutils import lorem, hard_wired_slice_names
@@ -26,12 +28,16 @@ def fake_slice_view (request, name=None):
 
 @login_required
 def tab_view (request):
-    return render_to_response ('view-tab.html',
-                               {'title':'Page for playing with Tabs',
-                                'topmenu_items': topmenu_items('tab',request),
-                                'username':the_user (request),
-                                'lorem': lorem,                                
-                                },
+    prelude=Prelude( js_files='bootstrap/js/bootstrap.js', css_files='bootstrap/css/bootstrap.css')
+    prelude_env = prelude.render_env()
+    tab_env = {'title':'Page for playing with Tabs',
+               'topmenu_items': topmenu_items('tab',request),
+               'username':the_user (request),
+               'lorem': lorem,                                
+               }
+    tab_env.update (prelude_env)
+
+    return render_to_response ('view-tab.html', tab_env,
                                context_instance=RequestContext(request))
 
 @login_required
index f8cdc10..679e746 100644 (file)
@@ -19,8 +19,6 @@
 
 {# let's add these ones no matter what #}
 {% insert_str prelude "jquery/js/jquery.js" %}
-{% insert_str prelude "bootstrap/js/bootstrap.js" %}
-{% insert_str prelude "bootstrap/css/bootstrap.css" %}
 {% insert_str prelude "js/plugin.js" %}
 {% insert_str prelude "css/myslice.css" %}
 
index be358f3..87a94e0 100644 (file)
@@ -8,7 +8,7 @@
 <ul class="nav nav-tabs" id='foo'>
   <li >                                <a href="#name1" data-toggle="tab">Here</a></li>
   <li class="active">          <a href="#name2" data-toggle="tab">Other</a></li>
-  </ul>
+</ul>
 <div class="tab-content">
    <div class="tab-pane fade in" id="name1">
      <p> {{ lorem|safe }} </p>