Mercurial > hg > ChinaGisRestApi
comparison RestDbInterface.py @ 8:a9a49f5765c9
reworking templates and schema
author | casties |
---|---|
date | Wed, 21 Jul 2010 17:01:04 +0200 |
parents | bd52d9445a41 |
children | 76ac7a721273 |
comparison
equal
deleted
inserted
replaced
7:bd52d9445a41 | 8:a9a49f5765c9 |
---|---|
34 | 34 |
35 # management templates | 35 # management templates |
36 manage_editRestDbInterfaceForm=PageTemplateFile('zpt/editRestDbInterface',globals()) | 36 manage_editRestDbInterfaceForm=PageTemplateFile('zpt/editRestDbInterface',globals()) |
37 | 37 |
38 # data templates | 38 # data templates |
39 XML_list_schemas = PageTemplateFile('zpt/XML_list_schemas', globals()) | 39 XML_index = PageTemplateFile('zpt/XML_index', globals()) |
40 XML_list_tables = PageTemplateFile('zpt/XML_list_tables', globals()) | 40 XML_schema = PageTemplateFile('zpt/XML_schema', globals()) |
41 XML_table = PageTemplateFile('zpt/XML_table', globals()) | 41 XML_schema_table = PageTemplateFile('zpt/XML_schema_table', globals()) |
42 HTML_list_schemas = PageTemplateFile('zpt/HTML_list_schemas', globals()) | 42 HTML_index = PageTemplateFile('zpt/HTML_index', globals()) |
43 HTML_list_tables = PageTemplateFile('zpt/HTML_list_tables', globals()) | 43 HTML_schema = PageTemplateFile('zpt/HTML_schema', globals()) |
44 HTML_table = PageTemplateFile('zpt/HTML_table', globals()) | 44 HTML_schema_table = PageTemplateFile('zpt/HTML_schema_table', globals()) |
45 | 45 |
46 | 46 |
47 | 47 |
48 def __init__(self, id, title, connection_id=None): | 48 def __init__(self, id, title, connection_id=None): |
49 """init""" | 49 """init""" |
106 #TODO: should we check more? | 106 #TODO: should we check more? |
107 else: | 107 else: |
108 # traverse | 108 # traverse |
109 if len(path) == 0: | 109 if len(path) == 0: |
110 # first segment | 110 # first segment |
111 if name in ['XML','JSON','HTML']: | 111 if name == 'db': |
112 # virtual path -- continue traversing | 112 # virtual path -- continue traversing |
113 path = [name] | 113 path = [name] |
114 request['restdb_path'] = path | 114 request['restdb_path'] = path |
115 else: | 115 else: |
116 # try real path | 116 # try real path |
123 # continue traversing | 123 # continue traversing |
124 return self | 124 return self |
125 | 125 |
126 def index_html(self,REQUEST,RESPONSE): | 126 def index_html(self,REQUEST,RESPONSE): |
127 """index method""" | 127 """index method""" |
128 # ReST path was stored in request | |
128 path = REQUEST.get('restdb_path',[]) | 129 path = REQUEST.get('restdb_path',[]) |
129 logging.debug("index_html path=%s"%path) | 130 # type and format are real parameter |
131 format = REQUEST.get('format','HTML').upper() | |
132 type = REQUEST.get('type',None) | |
133 logging.debug("index_html path=%s format=%s type=%s"%(path,format,type)) | |
134 | |
135 if type is not None: | |
136 # non-empty type -- look for template | |
137 pt = getattr(self.template, "%s_%s"%(format,type), None) | |
138 if pt is not None: | |
139 return pt(format=format,type=type,path=path) | |
140 | |
130 if len(path) == 1: | 141 if len(path) == 1: |
131 # list of schemas | 142 # list of schemas |
132 return self.showListOfSchemas(format=path[0]) | 143 return self.showListOfSchemas(format=format) |
133 elif len(path) == 2: | 144 elif len(path) == 2: |
134 # list of tables | 145 # list of tables |
135 return self.showListOfTables(format=path[0],schema=path[1]) | 146 return self.showListOfTables(format=format,schema=path[1]) |
136 elif len(path) == 3: | 147 elif len(path) == 3: |
137 # table | 148 # table |
138 return self.showTable(format=path[0],schema=path[1],table=path[2]) | 149 return self.showTable(format=format,schema=path[1],table=path[2]) |
139 | 150 |
140 # don't know what to do | 151 # don't know what to do |
141 return str(REQUEST) | 152 return str(REQUEST) |
142 | 153 |
143 | 154 |