add_result.py
branchxbelweb
changeset 3 9e7e8b678819
child 7 7cc3ab1c160b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/add_result.py	Tue Sep 23 15:11:11 2003 -0400
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+
+import sys
+import traceback
+sys.path.insert(0, "/home/fabien/lib/python")
+sys.path.insert(0, "./lib")
+sys.stderr = sys.stdout
+
+print "Content-type: text/html; charset=iso-8859-1;"
+print
+
+# import cgitb; cgitb.enable()
+import cgi
+from htmltmpl import TemplateManager, TemplateProcessor
+import my_db
+import time
+from bkmark import Bookmark
+
+def get_bk_from_form(form):
+	bk = Bookmark()
+	bk.url = form['url'].value
+	bk.name = form['name'].value
+	bk.desc = form['desc'].value
+	return bk
+
+def get_kw_from_form(form):
+	kw = form.getvalue("kw")
+	if not isinstance(kw, type([])):
+		if kw:
+			kw = [kw]
+		else:
+			kw = []
+	kw = map(int, kw)
+	return kw
+
+def main(bk, kw):
+    tmpl = TemplateManager().prepare("add_result.tmpl")
+    tproc = TemplateProcessor()
+    tproc.set("url", bk.url)
+    tproc.set("name", bk.name)
+    tproc.set("added", bk.added)
+    tproc.set("desc", bk.desc)
+    tproc.set("Keywords", kw)
+    print tproc.process(tmpl)
+
+if (__name__ == "__main__"):
+    form = cgi.FieldStorage()
+    db = my_db.connect()
+    bk = get_bk_from_form(form)
+    kw = get_kw_from_form(form)
+    id = db.add_bookmark(bk)
+    db.update_keywords(id, kw)
+    kw = map(lambda e: { 'keyword': e[1] }, db.get_keywords(id)[1:])
+    main(bk, kw)