diff -r 4cb6d9f3d3eb -r 9e7e8b678819 index.py --- a/index.py Tue Sep 23 10:26:35 2003 -0400 +++ b/index.py Tue Sep 23 15:11:11 2003 -0400 @@ -14,27 +14,42 @@ from htmltmpl import TemplateManager, TemplateProcessor import my_db -def main(msg): +def get_selection(form): + kw = form.getvalue("kw") + if not isinstance(kw, type([])): + if kw: + kw = [kw] + else: + kw = [0] + return map(int, kw) + +def set_selection(kw, sel): + res = [] + for key in kw: + chk = key[0] in sel + res.append({'id':key[0], + 'keyword': key[1], + 'checked' : chk}) + return res + +def main(bk, kw): tmpl = TemplateManager().prepare("index.tmpl") tproc = TemplateProcessor() - tproc.set("msg", msg) - -# tproc.set("syntax", user.syntax) -# for syntax in Tester.syntax_name: -# tproc.set("syntax_" + syntax, -# (Tester.syntax_name[user.syntax] == syntax)) -# tproc.set("id", user.id) -# tproc.set("gender", user.gender); -# tproc.set("age", user.age); -# exp = [] -# for key in Tester.keys: -# exp.append({ 'name' : key, -# 'value' : user.experience[key] }); -# tproc.set('Exp', exp); + tproc.set("Bookmarks", bk) + tproc.set("Keywords", kw) print tproc.process(tmpl) if (__name__ == "__main__"): form = cgi.FieldStorage() - cnx = my_db.connect() - qry = cnx.query('SELECT name FROM keywords;') - main(str(qry.getresult())) + db = my_db.connect() + keywords = db.get_all_keywords()[1:] + selection = get_selection(form) + if selection[0] == 0: + exc = map(lambda e: int(e[0]), keywords) + bookmarks = db.select_bookmarks([0], exc) + else: + bookmarks = db.select_bookmarks(selection) + keywords = set_selection(keywords, selection) + bookmarks = db.get_bookmarks(map(lambda x: x[0], bookmarks)) + bookmarks = map(lambda bk: bk.dict(), bookmarks) + main(bookmarks, keywords)