edit.py
author fabien
Fri, 17 Oct 2003 15:05:17 -0400
branchxbelweb
changeset 44 87f94936990d
parent 43 4d194fce51e1
child 47 2781ac85b807
permissions -rwxr-xr-x
[svn r1600] Add display name to preferences.

#!/usr/bin/python

import sys
import traceback
sys.path.insert(0, "/home/fabien/lib/python")
sys.path.insert(0, "./lib")
sys.stderr = sys.stdout

print "Content-type: text/html; charset=iso-8859-1;"
print

# import cgitb; cgitb.enable()
import cgi
from htmltmpl import TemplateManager
import my_db
import time
from bkmark import Bookmark
from webutils import get_template_processor
import os

def main(keywords, bk, prefs):
    tmpl = TemplateManager().prepare("add_bk.tmpl")
    tproc = get_template_processor(prefs)
    tproc.set('ctitle', bk.name)
    tproc.set('curl', bk.url)
    tproc.set('desc', bk.desc)
    tproc.set('bkid', bk.id)
    tproc.set('Keywords', keywords)
    print tproc.process(tmpl)

if (__name__ == "__main__"):
    form = cgi.FieldStorage()
    id = int(form["id"].value)
    db = my_db.connect(os.environ["REMOTE_USER"])
    bk = db.get_bookmarks([id])[0]
    kw = db.get_all_keywords()[1:]
    kw.sort(lambda l,r: cmp(l[1],r[1]))
    (ids, kws) = apply(zip,db.get_keywords([id]))
    kw = map(lambda elem: {
   	 'id' : elem[0],
   	 'keyword' : elem[1],
	 'selected' : elem[0] in ids }, kw)
    main(kw, bk, db.get_preferences())