Mercurial > hg > ChinaGisRestApi
diff RestDbInterface.py @ 8:a9a49f5765c9
reworking templates and schema
author | casties |
---|---|
date | Wed, 21 Jul 2010 17:01:04 +0200 |
parents | bd52d9445a41 |
children | 76ac7a721273 |
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)