# HG changeset patch # User casties # Date 1284019276 -7200 # Node ID 17dcf148beb344d914ef9f808b467ad30a7f3ad6 # Parent 29c822d15bc1aec753487e2203660cb9e3e4694d more JSON store diff -r 29c822d15bc1 -r 17dcf148beb3 RestDbJsonStore.py --- a/RestDbJsonStore.py Wed Sep 08 12:03:15 2010 +0200 +++ b/RestDbJsonStore.py Thu Sep 09 10:01:16 2010 +0200 @@ -178,11 +178,72 @@ sql = 'select distinct json_tag from "%s"."%s"'%(schema,table) res = self.executeSQL(sql) if len(res['rows']) > 0: - tags = [r[0] for r in rows] + tags = [r[0] for r in res['rows']] + return tags + + return [] + + def showListOfTypes(self,resultFormat,schema,table,tag): + """returns the list of existing types""" + types = self.getListOfTypes(schema, table,tag) + if resultFormat == 'JSON': + self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") + json.dump(types, self.REQUEST.RESPONSE) + else: + json.dump(types, self.REQUEST.RESPONSE) + + def getListOfTypes(self,schema,table,tag): + """returns the list of existing tags""" + logging.debug("getlistoftypes schema=%s table=%s tag=%s"%(schema,table,tag)) + sql = 'select distinct json_type from "%s"."%s" where json_tag = %%s'%(schema,table) + res = self.executeSQL(sql,(tag,)) + if len(res['rows']) > 0: + tags = [r[0] for r in res['rows']] return tags return [] + def showListOfItems(self,resultFormat,schema,table,tag,type): + """returns the list of existing items""" + items = self.getListOfItems(schema, table, tag, type) + if resultFormat == 'JSON': + self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") + json.dump(items, self.REQUEST.RESPONSE) + else: + json.dump(items, self.REQUEST.RESPONSE) + + def getListOfItems(self,schema,table,tag,type): + """returns the list of existing tags""" + logging.debug("getlistofitems schema=%s table=%s tag=%s type=%s"%(schema,table,tag,type)) + sql = 'select distinct json_item from "%s"."%s" where json_tag = %%s and json_type = %%s'%(schema,table) + res = self.executeSQL(sql,(tag,type)) + if len(res['rows']) > 0: + items = [r[0] for r in res['rows']] + return items + + return [] + + def showItem(self,resultFormat,schema,table,tag,type,item): + """returns the item""" + item = self.getItem(schema, table, tag, type, item) + if resultFormat == 'JSON': + self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") + json.dump(item, self.REQUEST.RESPONSE) + else: + json.dump(item, self.REQUEST.RESPONSE) + + def getItem(self,schema,table,tag,type,item): + """returns the list of existing tags""" + logging.debug("getitem schema=%s table=%s tag=%s type=%s item=%s"%(schema,table,tag,type,item)) + sql = 'select json_value from "%s"."%s" where json_tag = %%s and json_type = %%s and json_item = %%s'%(schema,table) + res = self.executeSQL(sql,(tag,type,item)) + if len(res['rows']) > 0: + # just one item + item = res['rows'][0][0] + return item + + return {} + manage_addRestDbJsonStoreForm=PageTemplateFile('zpt/addRestDbJsonStore',globals()) def manage_addRestDbJsonStore(self, id, title='', label='', description='',