changeset 8:a9a49f5765c9

reworking templates and schema
author casties
date Wed, 21 Jul 2010 17:01:04 +0200
parents bd52d9445a41
children 76ac7a721273
files RestDbInterface.py zpt/HTML_index.zpt zpt/HTML_list_schemas.zpt zpt/HTML_list_tables.zpt zpt/HTML_schema.zpt zpt/HTML_schema_table.zpt zpt/HTML_table.zpt zpt/XML_index.zpt zpt/XML_list_schemas.zpt zpt/XML_list_tables.zpt zpt/XML_schema.zpt zpt/XML_schema_table.zpt zpt/XML_table.zpt
diffstat 13 files changed, 107 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/RestDbInterface.py	Tue Jul 20 15:09:32 2010 +0200
+++ b/RestDbInterface.py	Wed Jul 21 17:01:04 2010 +0200
@@ -36,12 +36,12 @@
     manage_editRestDbInterfaceForm=PageTemplateFile('zpt/editRestDbInterface',globals())
 
     # data templates
-    XML_list_schemas = PageTemplateFile('zpt/XML_list_schemas', globals())
-    XML_list_tables = PageTemplateFile('zpt/XML_list_tables', globals())
-    XML_table = PageTemplateFile('zpt/XML_table', globals())
-    HTML_list_schemas = PageTemplateFile('zpt/HTML_list_schemas', globals())
-    HTML_list_tables = PageTemplateFile('zpt/HTML_list_tables', globals())
-    HTML_table = PageTemplateFile('zpt/HTML_table', globals())
+    XML_index = PageTemplateFile('zpt/XML_index', globals())
+    XML_schema = PageTemplateFile('zpt/XML_schema', globals())
+    XML_schema_table = PageTemplateFile('zpt/XML_schema_table', globals())
+    HTML_index = PageTemplateFile('zpt/HTML_index', globals())
+    HTML_schema = PageTemplateFile('zpt/HTML_schema', globals())
+    HTML_schema_table = PageTemplateFile('zpt/HTML_schema_table', globals())
 
     
     
@@ -108,7 +108,7 @@
             # traverse
             if len(path) == 0:
                 # first segment
-                if name in ['XML','JSON','HTML']:
+                if name == 'db':
                     # virtual path -- continue traversing
                     path = [name]
                     request['restdb_path'] = path
@@ -125,17 +125,28 @@
  
     def index_html(self,REQUEST,RESPONSE):
         """index method"""
+        # ReST path was stored in request
         path = REQUEST.get('restdb_path',[])
-        logging.debug("index_html path=%s"%path)
+        # type and format are real parameter
+        format = REQUEST.get('format','HTML').upper()
+        type = REQUEST.get('type',None)
+        logging.debug("index_html path=%s format=%s type=%s"%(path,format,type))
+
+        if type is not None:
+            # non-empty type -- look for template
+            pt = getattr(self.template, "%s_%s"%(format,type), None)
+            if pt is not None:
+                return pt(format=format,type=type,path=path)
+            
         if len(path) == 1:
             # list of schemas
-            return self.showListOfSchemas(format=path[0])
+            return self.showListOfSchemas(format=format)
         elif len(path) == 2:
             # list of tables
-            return self.showListOfTables(format=path[0],schema=path[1])
+            return self.showListOfTables(format=format,schema=path[1])
         elif len(path) == 3:
             # table
-            return self.showTable(format=path[0],schema=path[1],table=path[2])
+            return self.showTable(format=format,schema=path[1],table=path[2])
         
         # don't know what to do
         return str(REQUEST)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zpt/HTML_index.zpt	Wed Jul 21 17:01:04 2010 +0200
@@ -0,0 +1,21 @@
+<html tal:define="format python:request.get('format','table'); element_id python:request.get('element_id',None)">
+  <head>
+    <meta http-equiv="content-type" content="text/html;charset=utf-8">
+    <title tal:content="template/title">The title</title>
+  </head>
+  <body>
+    <h2>List of schemas</h2>
+    <tal:block tal:condition="python:format=='select'">
+    <select tal:attributes="id element_id">
+      <option tal:repeat="sch options/data/data" tal:content="sch"/>
+    </select>
+    </tal:block>
+    <tal:block tal:condition="python:format=='table'">
+    <table tal:attributes="id element_id">
+      <tr tal:repeat="sch options/data/data">
+        <td><a tal:attributes="href sch" tal:content="sch"/></td>
+      </tr>
+    </table>
+    </tal:block>
+  </body>
+</html>
\ No newline at end of file
--- a/zpt/HTML_list_schemas.zpt	Tue Jul 20 15:09:32 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-<html tal:define="format python:request.get('format','table'); element_id python:request.get('element_id',None)">
-  <head>
-    <meta http-equiv="content-type" content="text/html;charset=utf-8">
-    <title tal:content="template/title">The title</title>
-  </head>
-  <body>
-    <h2>List of schemas</h2>
-    <tal:block tal:condition="python:format=='select'">
-    <select tal:attributes="id element_id">
-      <option tal:repeat="sch options/data/data" tal:content="sch"/>
-    </select>
-    </tal:block>
-    <tal:block tal:condition="python:format=='table'">
-    <table tal:attributes="id element_id">
-      <tr tal:repeat="sch options/data/data">
-        <td><a tal:attributes="href sch" tal:content="sch"/></td>
-      </tr>
-    </table>
-    </tal:block>
-  </body>
-</html>
\ No newline at end of file
--- a/zpt/HTML_list_tables.zpt	Tue Jul 20 15:09:32 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-<html tal:define="format python:request.get('format','table'); element_id python:request.get('element_id',None)">
-  <head>
-    <meta http-equiv="content-type" content="text/html;charset=utf-8">
-    <title tal:content="template/title">The title</title>
-  </head>
-  <body>
-    <h2>List of tables for schema <span tal:replace="options/schema"/></h2>
-    <tal:block tal:condition="python:format=='select'">
-    <select tal:attributes="id element_id">
-      <option tal:repeat="tbl options/data/rows" tal:content="python:tbl[0]"/>
-    </select>
-    </tal:block>
-    <tal:block tal:condition="python:format=='table'">
-    <table tal:attributes="id element_id">
-      <tr tal:repeat="row options/data/rows">
-        <td><a tal:define="tbl python:row[0]" tal:attributes="href tbl" tal:content="tbl"/></td>
-      </tr>
-    </table>
-    </tal:block>
-  </body>
-</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zpt/HTML_schema.zpt	Wed Jul 21 17:01:04 2010 +0200
@@ -0,0 +1,21 @@
+<html tal:define="format python:request.get('format','table'); element_id python:request.get('element_id',None)">
+  <head>
+    <meta http-equiv="content-type" content="text/html;charset=utf-8">
+    <title tal:content="template/title">The title</title>
+  </head>
+  <body>
+    <h2>List of tables for schema <span tal:replace="options/schema"/></h2>
+    <tal:block tal:condition="python:format=='select'">
+    <select tal:attributes="id element_id">
+      <option tal:repeat="tbl options/data/rows" tal:content="python:tbl[0]"/>
+    </select>
+    </tal:block>
+    <tal:block tal:condition="python:format=='table'">
+    <table tal:attributes="id element_id">
+      <tr tal:repeat="row options/data/rows">
+        <td><a tal:define="tbl python:row[0]" tal:attributes="href tbl" tal:content="tbl"/></td>
+      </tr>
+    </table>
+    </tal:block>
+  </body>
+</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zpt/HTML_schema_table.zpt	Wed Jul 21 17:01:04 2010 +0200
@@ -0,0 +1,24 @@
+<html tal:define="format python:request.get('format','table'); element_id python:request.get('element_id',None); 
+    fields options/data/fields; rows options/data/rows;">
+  <head>
+    <meta http-equiv="content-type" content="text/html;charset=utf-8">
+    <title tal:content="template/title">The title</title>
+  </head>
+  <body>
+    <h2>table <span tal:replace="options/tablename"/></h2>
+    <tal:block tal:condition="python:format=='table'">
+    <table tal:attributes="id element_id">
+      <thead>
+        <tr>
+	      <th tal:repeat="field fields" tal:content="python:field[0]"/>
+        </tr>
+      </thead>
+      <tbody>
+        <tr tal:repeat="row rows">
+	      <td tal:repeat="col row" tal:content="col"/>
+        </tr>
+      </tbody>
+    </table>
+    </tal:block>
+  </body>
+</html>
\ No newline at end of file
--- a/zpt/HTML_table.zpt	Tue Jul 20 15:09:32 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-<html tal:define="format python:request.get('format','table'); element_id python:request.get('element_id',None); 
-    fields options/data/fields; rows options/data/rows;">
-  <head>
-    <meta http-equiv="content-type" content="text/html;charset=utf-8">
-    <title tal:content="template/title">The title</title>
-  </head>
-  <body>
-    <h2>table <span tal:replace="options/tablename"/></h2>
-    <tal:block tal:condition="python:format=='table'">
-    <table tal:attributes="id element_id">
-      <thead>
-        <tr>
-	      <th tal:repeat="field fields" tal:content="python:field[0]"/>
-        </tr>
-      </thead>
-      <tbody>
-        <tr tal:repeat="row rows">
-	      <td tal:repeat="col row" tal:content="col"/>
-        </tr>
-      </tbody>
-    </table>
-    </tal:block>
-  </body>
-</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zpt/XML_index.zpt	Wed Jul 21 17:01:04 2010 +0200
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<schemalist xmlns:tal="http://xml.zope.org/namespaces/tal">
+  <schema tal:repeat="sch options/data">
+	<name tal:content="sch"/>
+  </schema>
+</schemalist>
\ No newline at end of file
--- a/zpt/XML_list_schemas.zpt	Tue Jul 20 15:09:32 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<schemalist xmlns:tal="http://xml.zope.org/namespaces/tal">
-  <schema tal:repeat="sch options/data">
-	<name tal:content="sch"/>
-  </schema>
-</schemalist>
\ No newline at end of file
--- a/zpt/XML_list_tables.zpt	Tue Jul 20 15:09:32 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<tablelist xmlns:tal="http://xml.zope.org/namespaces/tal">
-  <table tal:repeat="tbl options/data">
-	<name tal:content="tbl/relname"/>
-  </table>
-</tablelist>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zpt/XML_schema.zpt	Wed Jul 21 17:01:04 2010 +0200
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<tablelist xmlns:tal="http://xml.zope.org/namespaces/tal">
+  <table tal:repeat="tbl options/data">
+	<name tal:content="tbl/relname"/>
+  </table>
+</tablelist>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zpt/XML_schema_table.zpt	Wed Jul 21 17:01:04 2010 +0200
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<table xmlns:tal="http://xml.zope.org/namespaces/tal" 
+  tal:define="fields options/data/names" tal:attributes="name options/tablename">
+  <row tal:repeat="row options/data">
+	<column tal:repeat="field fields" tal:attributes="name field" tal:content="python:row[field]"/>
+  </row>
+</table>
--- a/zpt/XML_table.zpt	Tue Jul 20 15:09:32 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<table xmlns:tal="http://xml.zope.org/namespaces/tal" 
-  tal:define="fields options/data/names" tal:attributes="name options/tablename">
-  <row tal:repeat="row options/data">
-	<column tal:repeat="field fields" tal:attributes="name field" tal:content="python:row[field]"/>
-  </row>
-</table>