[Kimchi-devel] [PATCH v2][Wok 6/8] Fix Sample plugin

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Mon Jun 6 19:13:34 UTC 2016


This patch adapts Sample plugin to work with new latest Wok plugin
changes and to work with Plugins Manager.
---
 src/wok/plugins/sample/__init__.py                 | 54 ++++++++++++++++++++--
 src/wok/plugins/sample/control/__init__.py         | 26 +++++++++++
 src/wok/plugins/sample/sample.conf.in              | 22 ---------
 src/wok/plugins/sample/ui/config/tab-ext.xml       |  9 ++--
 .../plugins/sample/ui/pages/sample-tab1.html.tmpl  |  3 ++
 .../plugins/sample/ui/pages/sample-tab2.html.tmpl  |  3 ++
 6 files changed, 86 insertions(+), 31 deletions(-)
 create mode 100644 src/wok/plugins/sample/control/__init__.py

diff --git a/src/wok/plugins/sample/__init__.py b/src/wok/plugins/sample/__init__.py
index ff96b15..c65dd0d 100644
--- a/src/wok/plugins/sample/__init__.py
+++ b/src/wok/plugins/sample/__init__.py
@@ -23,21 +23,22 @@ import json
 import os
 from cherrypy import expose
 
-
-from wok.config import PluginPaths
+from wok.config import CACHEEXPIRES, PluginConfig, PluginPaths
 from wok.control.base import Collection, Resource
 from wok.root import WokRoot
 
 
-from plugins.sample.i18n import messages
-from plugins.sample.model import Model
+from wok.plugins.sample.i18n import messages
+from wok.plugins.sample.model import Model
 
 
 model = Model()
 
 
-class Drawings(WokRoot):
+class Sample(WokRoot):
     def __init__(self, wok_options):
+        dev_env = wok_options.environment != 'production'
+        super(Sample, self).__init__(model, dev_env)
         Resource.__init__(self, model)
         self.description = Description(model)
         self.rectangles = Rectangles(model)
@@ -52,6 +53,49 @@ class Drawings(WokRoot):
     def index(self):
         return 'This is a sample plugin for Wok'
 
+    def get_custom_conf(self):
+        return SampleConfig()
+
+
+class SampleConfig(PluginConfig):
+    def __init__(self):
+        super(SampleConfig, self).__init__('sample')
+
+        sample_path = PluginPaths('sample')
+
+        custom_config = {
+            '/help': {
+                'tools.staticdir.on': True,
+                'tools.staticdir.dir': os.path.join(sample_path.ui_dir,
+                                                    'pages/help'),
+                'tools.nocache.on': True
+            },
+            '/images': {
+                'tools.staticdir.on': True,
+                'tools.staticdir.dir': os.path.join(sample_path.ui_dir,
+                                                    'images'),
+                'tools.wokauth.on': False,
+                'tools.nocache.on': False
+            },
+            '/description': {'tools.wokauth.on': True},
+            '/rectangles': {'tools.wokauth.on':  True},
+            '/circles': {'tools.wokauth.on':  True}
+        }
+
+        for dirname in ('css', 'js', 'images'):
+            custom_config['/' + dirname] = {
+                'tools.staticdir.on': True,
+                'tools.staticdir.dir': os.path.join(sample_path.ui_dir,
+                                                    dirname),
+                'tools.wokauth.on': False,
+                'tools.nocache.on': False}
+            if dirname != 'images':
+                custom_config['/' + dirname].update({
+                    'tools.expires.on': True,
+                    'tools.expires.secs': CACHEEXPIRES})
+
+        self.update(custom_config)
+
 
 class Description(Resource):
     def __init__(self, model):
diff --git a/src/wok/plugins/sample/control/__init__.py b/src/wok/plugins/sample/control/__init__.py
new file mode 100644
index 0000000..c87776e
--- /dev/null
+++ b/src/wok/plugins/sample/control/__init__.py
@@ -0,0 +1,26 @@
+#
+# Project Wok
+#
+# Copyright IBM Corp, 2016
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+import os
+
+
+from wok.control.utils import load_url_sub_node
+
+
+sub_nodes = load_url_sub_node(os.path.dirname(__file__), __name__)
diff --git a/src/wok/plugins/sample/sample.conf.in b/src/wok/plugins/sample/sample.conf.in
index 9da33e1..1e1b8a4 100644
--- a/src/wok/plugins/sample/sample.conf.in
+++ b/src/wok/plugins/sample/sample.conf.in
@@ -1,27 +1,5 @@
 [wok]
 enable = @ENABLE_SAMPLE@
-plugin_class = "Drawings"
 uri = "/plugins/sample"
 
-[/]
-tools.nocache.on = True
-tools.trailing_slash.on = False
-tools.sessions.on = True
-tools.sessions.name = 'wok'
-tools.sessions.httponly = True
-tools.sessions.locking = 'explicit'
-tools.sessions.storage_type = 'ram'
 
-[/description]
-tools.wokauth.on = True
-
-[/rectangles]
-tools.wokauth.on = True
-
-[/circles]
-tools.wokauth.on = True
-
-[/help]
-tools.staticdir.on = True
-tools.nocache.on = True
-tools.staticdir.dir = wok.config.PluginPaths('sample').ui_dir + '/pages/help'
diff --git a/src/wok/plugins/sample/ui/config/tab-ext.xml b/src/wok/plugins/sample/ui/config/tab-ext.xml
index aff0d14..bcd20fe 100644
--- a/src/wok/plugins/sample/ui/config/tab-ext.xml
+++ b/src/wok/plugins/sample/ui/config/tab-ext.xml
@@ -1,17 +1,18 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tabs-ext>
+    <functionality>Sample</functionality>
     <tab>
         <access role="admin" mode="admin"/>
         <access role="user" mode="none"/>
-
-        <title>SampleTab 1</title>
+        <title>SampleTab1</title>
         <path>plugins/sample/sample-tab1.html</path>
+        <order>10</order>
     </tab>
     <tab>
         <access role="admin" mode="admin"/>
         <access role="user" mode="none"/>
-
-        <title>SampleTab 2</title>
+        <title>SampleTab2</title>
         <path>plugins/sample/sample-tab2.html</path>
+        <order>20</order>
     </tab>
 </tabs-ext>
diff --git a/src/wok/plugins/sample/ui/pages/sample-tab1.html.tmpl b/src/wok/plugins/sample/ui/pages/sample-tab1.html.tmpl
index 2777848..8e4b52b 100644
--- a/src/wok/plugins/sample/ui/pages/sample-tab1.html.tmpl
+++ b/src/wok/plugins/sample/ui/pages/sample-tab1.html.tmpl
@@ -22,6 +22,9 @@
 <html>
 <script type="text/javascript" src="plugins/sample/js/util.js"></script>
 <body>
+    <div>
+    Sample PAGE 1
+    </div>
     <div id="samplebody"/>
 </body>
 <script>
diff --git a/src/wok/plugins/sample/ui/pages/sample-tab2.html.tmpl b/src/wok/plugins/sample/ui/pages/sample-tab2.html.tmpl
index 2777848..8f92b80 100644
--- a/src/wok/plugins/sample/ui/pages/sample-tab2.html.tmpl
+++ b/src/wok/plugins/sample/ui/pages/sample-tab2.html.tmpl
@@ -22,6 +22,9 @@
 <html>
 <script type="text/javascript" src="plugins/sample/js/util.js"></script>
 <body>
+    <div>
+    Sample PAGE 2
+    </div>
     <div id="samplebody"/>
 </body>
 <script>
-- 
2.1.0




More information about the Kimchi-devel mailing list