--- a/index.py Fri Sep 26 11:31:09 2003 -0400
+++ b/index.py Fri Sep 26 18:18:33 2003 -0400
@@ -26,23 +26,27 @@
kw = [0]
return map(int, kw)
-def set_selection(kw, sel):
+def set_selection(db, sel):
+ allkw = db.get_all_keywords()
+ (kw, cnt) = map(list,apply(zip, db.get_keywords_count()))
res = []
- for key in kw:
+ for key in allkw:
chk = key[0] in sel
+ if key[0] in kw:
+ kcnt = cnt[kw.index(key[0])]
+ else:
+ kcnt = 0
res.append({'id':key[0],
'keyword': key[1],
- 'count' : key[2],
+ 'count' : kcnt,
'checked' : chk})
- res.sort(lambda l,r: cmp(l["keyword"],r["keyword"]))
return res
def get_curl():
return urljoin( 'http://' + environ["HTTP_HOST"] + environ["REQUEST_URI"], 'add.py')
def load_index(db):
- kw = db.get_all_keywords()
- kw = set_selection(kw, [])
+ kw = set_selection(db, [])
total = kw[0]['count']
kw = kw[1:]
exc = map(lambda e: int(e['id']), kw)
@@ -56,7 +60,10 @@
def main(bk, kw, curl, total):
tmpl = TemplateManager().prepare("index.tmpl")
tproc = TemplateProcessor()
+ tproc.set("pagetitle", environ["REMOTE_USER"]+"'s XBELWeb")
+ bk.sort(lambda x,y: cmp(x['name'],y['name']))
tproc.set("Bookmarks", bk)
+ kw.sort(lambda x,y: cmp(x['keyword'],y['keyword']))
tproc.set("Keywords", kw)
tproc.set("curl", curl)
tproc.set("total", total)
@@ -64,17 +71,16 @@
if (__name__ == "__main__"):
form = cgi.FieldStorage()
- db = my_db.connect()
- keywords = db.get_all_keywords()
- total = keywords[0][2]
+ db = my_db.connect(environ["REMOTE_USER"])
+ selection = get_selection(form)
+ keywords = set_selection(db, selection)
+ total = keywords[0]['count']
keywords = keywords[1:]
- selection = get_selection(form)
if selection[0] == 0:
- exc = map(lambda e: int(e[0]), keywords)
+ exc = map(lambda e: int(e['id']), keywords)
bookmarks = db.select_bookmarks([0], exc)
else:
bookmarks = db.select_bookmarks(selection)
- keywords = set_selection(keywords, selection)
if len(bookmarks) > 0:
bookmarks = db.get_bookmarks(map(lambda x: x[0], bookmarks))
bookmarks = map(lambda bk: bk.dict(), bookmarks)