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 templates import Template |
|
15 import my_db |
|
16 import time |
|
17 from bkmark import Bookmark |
|
18 import os |
|
19 |
|
20 def main(keywords, bk, prefs): |
|
21 tmpl = Template("add_bk.tmpl", prefs) |
|
22 tmpl.set('ctitle', bk.name) |
|
23 tmpl.set('curl', bk.url) |
|
24 tmpl.set('desc', bk.desc) |
|
25 tmpl.set('bkid', bk.id) |
|
26 tmpl.set('Keywords', keywords) |
|
27 print tmpl.process() |
|
28 |
|
29 if (__name__ == "__main__"): |
|
30 form = cgi.FieldStorage() |
|
31 id = int(form["id"].value) |
|
32 db = my_db.connect(os.environ["REMOTE_USER"]) |
|
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 'selected' : elem[0] in ids }, kw) |
|
41 main(kw, bk, db.get_preferences()) |
|