author | fabien |
Wed, 24 Sep 2003 14:28:47 -0400 | |
branch | xbelweb |
changeset 7 | 7cc3ab1c160b |
parent 6 | da757ef67c69 |
child 9 | 896b7c6de627 |
permissions | -rwxr-xr-x |
0 | 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 |
||
11 |
||
12 |
# import cgitb; cgitb.enable() |
|
13 |
import cgi |
|
14 |
from htmltmpl import TemplateManager, TemplateProcessor |
|
15 |
import my_db |
|
4 | 16 |
from os import environ |
17 |
from urlparse import urljoin |
|
0 | 18 |
|
3 | 19 |
def get_selection(form): |
20 |
kw = form.getvalue("kw") |
|
21 |
if not isinstance(kw, type([])): |
|
22 |
if kw: |
|
23 |
kw = [kw] |
|
24 |
else: |
|
25 |
kw = [0] |
|
26 |
return map(int, kw) |
|
27 |
||
28 |
def set_selection(kw, sel): |
|
29 |
res = [] |
|
30 |
for key in kw: |
|
31 |
chk = key[0] in sel |
|
32 |
res.append({'id':key[0], |
|
33 |
'keyword': key[1], |
|
34 |
'checked' : chk}) |
|
35 |
return res |
|
36 |
||
4 | 37 |
def get_curl(): |
38 |
return urljoin( 'http://' + environ["HTTP_HOST"] + environ["REQUEST_URI"], 'add.py') |
|
39 |
||
40 |
def main(bk, kw, curl): |
|
0 | 41 |
tmpl = TemplateManager().prepare("index.tmpl") |
42 |
tproc = TemplateProcessor() |
|
3 | 43 |
tproc.set("Bookmarks", bk) |
44 |
tproc.set("Keywords", kw) |
|
4 | 45 |
tproc.set("curl", curl) |
0 | 46 |
print tproc.process(tmpl) |
47 |
||
48 |
if (__name__ == "__main__"): |
|
49 |
form = cgi.FieldStorage() |
|
3 | 50 |
db = my_db.connect() |
51 |
keywords = db.get_all_keywords()[1:] |
|
52 |
selection = get_selection(form) |
|
53 |
if selection[0] == 0: |
|
54 |
exc = map(lambda e: int(e[0]), keywords) |
|
55 |
bookmarks = db.select_bookmarks([0], exc) |
|
56 |
else: |
|
57 |
bookmarks = db.select_bookmarks(selection) |
|
58 |
keywords = set_selection(keywords, selection) |
|
6
da757ef67c69
[svn r1540] Correction for zero-lenght results in bookmark search.
fabien
parents:
4
diff
changeset
|
59 |
if len(bookmarks) > 0: |
da757ef67c69
[svn r1540] Correction for zero-lenght results in bookmark search.
fabien
parents:
4
diff
changeset
|
60 |
bookmarks = db.get_bookmarks(map(lambda x: x[0], bookmarks)) |
3 | 61 |
bookmarks = map(lambda bk: bk.dict(), bookmarks) |
4 | 62 |
curl = get_curl(); |
63 |
main(bookmarks, keywords, curl) |