changeset 45:ed8db63fab4f

more refactoring of templates
author casties
date Thu, 02 Sep 2010 17:01:52 +0200
parents c6c47034d2a4
children 3ea606bae008 698ef00f2717
files RestDbInterface.py zpt/HTML_index.zpt zpt/HTML_schema.zpt zpt/HTML_schema_table.zpt zpt/JSONHTML_index.zpt zpt/JSONHTML_schema.zpt zpt/XML_index.zpt zpt/XML_schema.zpt
diffstat 8 files changed, 30 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/RestDbInterface.py	Thu Sep 02 16:38:50 2010 +0200
+++ b/RestDbInterface.py	Thu Sep 02 17:01:52 2010 +0200
@@ -87,15 +87,15 @@
     JSONHTML_schema = PageTemplateFile('zpt/JSONHTML_schema', globals())
     JSONHTML_schema_table = PageTemplateFile('zpt/JSONHTML_schema_table', globals())
     # JSON_* templates are scripts
-    def JSON_index(self,data):
+    def JSON_index(self):
         """JSON index function"""
         self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
-        json.dump(data, self.REQUEST.RESPONSE)        
+        json.dump(self.getListOfSchemas(), self.REQUEST.RESPONSE)        
 
-    def JSON_schema(self,data,schema):
+    def JSON_schema(self,schema):
         """JSON index function"""
         self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
-        json.dump(data, self.REQUEST.RESPONSE)        
+        json.dump(self.getListOfTables(schema), self.REQUEST.RESPONSE)        
 
     def JSON_schema_table(self,schema,table):
         """JSON index function"""
@@ -324,8 +324,8 @@
         if pt is None:
             return "ERROR!! template %s_schema not found"%resultFormat
         
-        data = self.getListOfTables(schema)
-        return pt(data=data,schema=schema)
+        #data = self.getListOfTables(schema)
+        return pt(schema=schema)
  
     def getListOfTables(self,schema='public',username='guest'):
         """return list of tables"""
@@ -351,8 +351,8 @@
         if pt is None:
             return "ERROR!! template %s_index not found"%resultFormat
         
-        data = self.getListOfSchemas()
-        return pt(data=data)
+        #data = self.getListOfSchemas()
+        return pt()
  
     def getListOfSchemas(self,username='guest'):
         """return list of schemas"""
--- a/zpt/HTML_index.zpt	Thu Sep 02 16:38:50 2010 +0200
+++ b/zpt/HTML_index.zpt	Thu Sep 02 17:01:52 2010 +0200
@@ -1,4 +1,5 @@
-<html tal:define="layout python:request.get('layout','table'); element_id python:request.get('element_id',None)">
+<html tal:define="layout python:request.get('layout','table'); element_id python:request.get('element_id',None);
+  data here/getListOfSchemas">
   <head>
     <meta http-equiv="content-type" content="text/html;charset=utf-8">
     <title tal:content="template/title">The title</title>
@@ -7,12 +8,12 @@
     <h2>List of schemas</h2>
     <tal:block tal:condition="python:layout=='select'">
     <select tal:attributes="id element_id">
-      <option tal:repeat="sch options/data/data" tal:content="sch"/>
+      <option tal:repeat="sch data/data" tal:content="sch"/>
     </select>
     </tal:block>
     <tal:block tal:condition="python:layout=='table'">
     <table tal:attributes="id element_id">
-      <tr tal:repeat="row options/data/rows">
+      <tr tal:repeat="row data/rows">
         <td><a tal:define="sch python:row[0]" tal:attributes="href sch" tal:content="sch"/></td>
       </tr>
     </table>
--- a/zpt/HTML_schema.zpt	Thu Sep 02 16:38:50 2010 +0200
+++ b/zpt/HTML_schema.zpt	Thu Sep 02 17:01:52 2010 +0200
@@ -1,18 +1,19 @@
-<html tal:define="layout python:request.get('layout','table'); element_id python:request.get('element_id',None)">
+<html tal:define="layout python:request.get('layout','table'); element_id python:request.get('element_id',None);
+  schema options/schema; data python:here.getListOfTables(schema)">
   <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>
+    <h2>List of tables for schema <span tal:replace="schema"/></h2>
     <tal:block tal:condition="python:layout=='select'">
     <select tal:attributes="id element_id">
-      <option tal:repeat="tbl options/data/rows" tal:content="python:tbl[0]"/>
+      <option tal:repeat="tbl data/rows" tal:content="python:tbl[0]"/>
     </select>
     </tal:block>
     <tal:block tal:condition="python:layout=='table'">
     <table tal:attributes="id element_id">
-      <tr tal:repeat="row options/data/rows">
+      <tr tal:repeat="row data/rows">
         <td><a tal:define="tbl python:row[0]" tal:attributes="href tbl" tal:content="tbl"/></td>
       </tr>
     </table>
--- a/zpt/HTML_schema_table.zpt	Thu Sep 02 16:38:50 2010 +0200
+++ b/zpt/HTML_schema_table.zpt	Thu Sep 02 17:01:52 2010 +0200
@@ -6,7 +6,7 @@
     <title tal:content="template/title">The title</title>
   </head>
   <body>
-    <h2>table <span tal:replace="options/tablename"/></h2>
+    <h2>table <span tal:replace="table"/></h2>
     <tal:block tal:condition="python:layout=='table'">
     <table tal:attributes="id element_id">
       <thead>
--- a/zpt/JSONHTML_index.zpt	Thu Sep 02 16:38:50 2010 +0200
+++ b/zpt/JSONHTML_index.zpt	Thu Sep 02 17:01:52 2010 +0200
@@ -1,9 +1,10 @@
-<html tal:define="layout python:request.get('layout','pre'); element_id python:request.get('element_id',None)">
+<html tal:define="layout python:request.get('layout','pre'); element_id python:request.get('element_id',None);
+  data here/getListOfSchemas">
   <head>
     <meta http-equiv="content-type" content="text/html;charset=utf-8">
     <title tal:content="template/title">The title</title>
   </head>
   <body>
-  <pre tal:attributes="id element_id" tal:content="python:here.getJsonString(options['data'])"></pre>
+  <pre tal:attributes="id element_id" tal:content="python:here.getJsonString(data)"></pre>
   </body>
 </html>
\ No newline at end of file
--- a/zpt/JSONHTML_schema.zpt	Thu Sep 02 16:38:50 2010 +0200
+++ b/zpt/JSONHTML_schema.zpt	Thu Sep 02 17:01:52 2010 +0200
@@ -1,9 +1,10 @@
-<html tal:define="layout python:request.get('layout','pre'); element_id python:request.get('element_id',None)">
+<html tal:define="layout python:request.get('layout','pre'); element_id python:request.get('element_id',None);
+  schema options/schema; data python:here.getListOfTables(schema)">
   <head>
     <meta http-equiv="content-type" content="text/html;charset=utf-8">
     <title tal:content="template/title">The title</title>
   </head>
   <body>
-  <pre tal:attributes="id element_id" tal:content="python:here.getJsonString(options['data'])"></pre>
+  <pre tal:attributes="id element_id" tal:content="python:here.getJsonString(data)"></pre>
   </body>
 </html>
\ No newline at end of file
--- a/zpt/XML_index.zpt	Thu Sep 02 16:38:50 2010 +0200
+++ b/zpt/XML_index.zpt	Thu Sep 02 17:01:52 2010 +0200
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
-<schemalist xmlns:tal="http://xml.zope.org/namespaces/tal">
-  <schema tal:repeat="row options/data/rows">
+<schemalist xmlns:tal="http://xml.zope.org/namespaces/tal"
+  tal:define="data here/getListOfSchemas">
+  <schema tal:repeat="row data/rows">
 	<name tal:content="python:row[0]"/>
   </schema>
 </schemalist>
\ No newline at end of file
--- a/zpt/XML_schema.zpt	Thu Sep 02 16:38:50 2010 +0200
+++ b/zpt/XML_schema.zpt	Thu Sep 02 17:01:52 2010 +0200
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
-<tablelist xmlns:tal="http://xml.zope.org/namespaces/tal">
-  <table tal:repeat="row options/data/rows">
+<tablelist xmlns:tal="http://xml.zope.org/namespaces/tal"
+  tal:define="schema options/schema; data python:here.getListOfTables(schema)">
+  <table tal:repeat="row data/rows">
 	<name tal:content="python:row[0]"/>
   </table>
 </tablelist>
\ No newline at end of file