3 import os, sys, string, time, getopt
6 import neo_cgi, neo_cs, neo_util
7 import odb, hdfhelp, CSPage
15 pathinfo = hdf.getValue(
"CGI.PathInfo",
"")
20 pathparts = string.split(pathinfo,
"/")
23 methodName = pathparts[0]
28 modpath, f = os.path.split(os.path.abspath(__file__) )
29 templatePath = os.path.join(modpath,
"templates")
34 method = getattr(self, methodName)
41 hdf.setValue(
"CGI.cur.title",
"List %s Table" % self.
tableName)
47 tbl = self.
db[tableName]
48 tableColumnlist = tbl.getColumnList()
52 for col, d, colinfo
in tableColumnlist:
53 if colinfo.has_key(
"foreign_table"):
54 foreign_table = colinfo[
"foreign_table"]
56 columnlist.append((
"_" + col +
"." +
"name", d, colinfo))
58 columnlist.append((col, d, colinfo))
59 rows = tbl.fetchRows(join2=joins)
62 primaryKeys = tbl.getPrimaryKeyList()
67 aprefix = prefix +
".rows.%s" % n
68 self.
__exportRow(row, columnlist, hdf, aprefix, primaryKeys)
71 for col_name,col_type,options
in columnlist:
72 col_name = col_name.replace(
".",
"_")
73 if options.get(
"no_export", 0):
continue 74 aprefix = prefix +
".fields.%s" % col_name
75 hdf.setValue(aprefix +
".name", col_name)
77 hdf.setValue(aprefix +
".col_type", col_type.odbType())
78 hdfhelp.hdfExportDict(aprefix +
".options", hdf, options)
81 def __exportRow(self, row, columnlist, hdf, prefix, primaryKeys):
83 for col_name,col_type,options
in columnlist:
84 if options.get(
"no_export", 0):
continue 86 a_col_name = col_name.replace(
".",
"_")
87 nprefix = prefix +
".values." + a_col_name
89 value = row.get(col_name,
"")
93 hdf.setValue(nprefix, str(value))
95 hdf.setValue(nprefix,
"")
102 key.append(
"%s=%s" % (k, str(val)))
103 hdf.setValue(prefix +
".key", string.join(key,
"&"))
107 node = hdf.getObj(
"Query")
111 if node.name()
not in (
"debug", ):
112 fields[node.name()] = node.value()
114 fields = fields.items()
120 row = tbl.fetchRow(fields)
126 hdf.setValue(
"CGI.cur.action",
"edit")
131 columnlist = tbl.getColumnList()
133 hdf.setValue(
"CGI.cur.title",
"Edit %s" % self.
tableName)
137 hdf.setValue(
"CGI.cur.action",
"new")
142 node = hdf.getObj(
"Query.values")
146 row[node.name()] = node.value()
153 key = hdf.getValue(
"Query.key",
"")
154 if not key:
return []
155 parts = key.split(
"&")
158 kvparts = part.split(
"=", 1)
159 keylist.append((kvparts[0], kvparts[1]))
163 hdf.setValue(
"CGI.cur.action",
"edit")
165 node = hdf.getObj(
"Query.values")
169 dict[node.name()] = node.value()
175 row = tbl.fetchRow(keylist)
177 for k,v
in dict.items():
183 hdf.setValue(
"CGI.cur.title",
"New %s Row" % self.
tableName)
185 hdf.setValue(
"CGI.cur.action",
"new")
189 prefix =
"CGI.cur.row" 190 columnlist = tbl.getColumnList()
192 primaryKeys = tbl.getPrimaryKeyList()
193 self.
__exportRow(row, columnlist, hdf,
"CGI.cur.row", primaryKeys)
199 hdf.setValue(
"CGI.cur.title",
"Show %s" % self.
tableName)
204 row = tbl.fetchRow(fields)
206 columnlist = tbl.getColumnList()
207 primaryKeys = tbl.getPrimaryKeyList()
208 self.
__exportRow(row, columnlist, hdf,
"CGI.cur.row", primaryKeys)
217 pathinfo = hdf.getValue(
"CGI.PathInfo",
"")
224 pathparts = string.split(pathinfo,
"/")
227 if len(pathparts) >= 1:
229 if len(pathparts) == 2:
239 tables = self.db.getTableList()
241 hdfhelp.hdfExportList(
"CGI.cur.tables", hdf, tables)
242 Scaffold.display(self, hdf)
255 hdf.setValue(
"CGI.cur.title",
"List DB Tables")
265 print __doc__ % vars()
267 def main(argv, stdout, environ):
269 optlist, args = getopt.getopt(argv[1:],
"", [
"help",
"test",
"debug"])
275 for (field, val)
in optlist:
276 if field ==
"--help":
279 elif field ==
"--debug":
281 elif field ==
"--test":
289 if __name__ ==
"__main__":
290 main(sys.argv, sys.stdout, os.environ)
def redirectUri(self, redirectTo)
def setPaths(self, paths)
def Action_edit(self, hdf)
def setupDetails(self, db, tableName)
def __listTable(self, hdf, tableName, prefix)
def __exportColumnHeaders(self, columnlist, hdf, prefix)
def __findKeyFromQuery(self, hdf)
def setupDetails(self, db)
def main(argv, stdout, environ)
def __exportRow(self, row, columnlist, hdf, prefix, primaryKeys)
def activate(self, hdf, methodName)
def Action_new(self, hdf)
def getKeyFromQuery(self, hdf)