|
1 #!/usr/bin/python |
|
2 |
|
3 import sys |
|
4 import traceback |
|
5 sys.path.insert(0, "/home/fabien/lib/python") |
|
6 sys.path.insert(0, "./lib") |
|
7 sys.stderr = sys.stdout |
|
8 |
|
9 print "Content-type: text/html; charset=iso-8859-1;" |
|
10 print |
|
11 |
|
12 # import cgitb; cgitb.enable() |
|
13 import cgi |
|
14 from htmltmpl import TemplateManager, TemplateProcessor |
|
15 import my_db |
|
16 import time |
|
17 from bkmark import Bookmark |
|
18 |
|
19 def main(keywords, bk): |
|
20 tmpl = TemplateManager().prepare("add_bk.tmpl") |
|
21 tproc = TemplateProcessor() |
|
22 tproc.set('ctitle', bk.name) |
|
23 tproc.set('curl', bk.url) |
|
24 tproc.set('desc', bk.desc) |
|
25 tproc.set('bkid', bk.id) |
|
26 tproc.set('Keywords', keywords) |
|
27 print tproc.process(tmpl) |
|
28 |
|
29 if (__name__ == "__main__"): |
|
30 form = cgi.FieldStorage() |
|
31 id = int(form["id"].value) |
|
32 db = my_db.connect() |
|
33 bk = db.get_bookmarks([id])[0] |
|
34 kw = db.get_all_keywords()[1:] |
|
35 kw.sort(lambda l,r: cmp(l[1],r[1])) |
|
36 (ids, kws) = apply(zip,db.get_keywords(id)) |
|
37 kw = map(lambda elem: { |
|
38 'id' : elem[0], |
|
39 'keyword' : elem[1], |
|
40 'checked' : elem[0] in ids }, kw) |
|
41 main(kw, bk) |