add_confirm.py
branchxbelweb
changeset 47 2781ac85b807
parent 43 4d194fce51e1
equal deleted inserted replaced
46:d3c1de4d929e 47:2781ac85b807
    11 	print "Content-type: text/html; charset=iso-8859-1;"
    11 	print "Content-type: text/html; charset=iso-8859-1;"
    12 	print
    12 	print
    13 
    13 
    14 # import cgitb; cgitb.enable()
    14 # import cgitb; cgitb.enable()
    15 import cgi
    15 import cgi
    16 from htmltmpl import TemplateManager
       
    17 from webutils import get_template_processor
       
    18 import my_db
    16 import my_db
    19 import time
    17 import time
    20 from bkmark import Bookmark
    18 from bkmark import Bookmark
    21 from index import load_index
    19 from webutils import load_index
       
    20 from templates import Template
    22 from utils import unique
    21 from utils import unique
    23 import os
    22 import os
    24 
    23 
    25 def get_bk_from_form(form):
    24 def get_bk_from_form(form):
    26 	bk = Bookmark()
    25 	bk = Bookmark()
    56       kw = kw + get_new_kw_from_form(form)
    55       kw = kw + get_new_kw_from_form(form)
    57       kw = unique(kw) 
    56       kw = unique(kw) 
    58       return kw
    57       return kw
    59 
    58 
    60 def main(action, bk, kw, prefs):
    59 def main(action, bk, kw, prefs):
    61     tmpl = TemplateManager().prepare("add_confirm.tmpl")
    60     tmpl = Template("add_confirm.tmpl", prefs)
    62     tproc = get_template_processor(prefs)
    61     tmpl.set("confirm_delete", action == 'delete')
    63     tproc.set("confirm_delete", action == 'delete')
    62     tmpl.set("confirm_update", action == 'update')
    64     tproc.set("confirm_update", action == 'update')
    63     tmpl.set("action", action)
    65     tproc.set("action", action)
    64     tmpl.set("id", bk.id)
    66     tproc.set("id", bk.id)
    65     tmpl.set("name", bk.name)
    67     tproc.set("name", bk.name)
    66     tmpl.set("url", bk.url)
    68     tproc.set("url", bk.url)
    67     tmpl.set("Keywords", map(lambda x: {'keyword': x }, kw))
    69     tproc.set("Keywords", map(lambda x: {'keyword': x }, kw))
    68     print tmpl.process()
    70     print tproc.process(tmpl)
       
    71 
    69 
    72 if (__name__ == "__main__"):
    70 if (__name__ == "__main__"):
    73     form = cgi.FieldStorage()
    71     form = cgi.FieldStorage()
    74     db = my_db.connect(os.environ["REMOTE_USER"])
    72     db = my_db.connect(os.environ["REMOTE_USER"])
       
    73     prefs = db.get_preferences()
    75     id = int(form['id'].value)
    74     id = int(form['id'].value)
    76     action = form['action'].value
    75     action = form['action'].value
    77     if action == 'cancel' or (action == 'delete' and id == -1):
    76     if action == 'cancel' or (action == 'delete' and id == -1):
    78         load_index(db)
    77         load_index(db, prefs)
    79     else:
    78     else:
    80 	if action == 'update':
    79 	if action == 'update':
    81 	  bk = get_bk_from_form(form)
    80 	  bk = get_bk_from_form(form)
    82 	  kw = get_unique_keywords(form, db)
    81 	  kw = get_unique_keywords(form, db)
    83 	else:
    82 	else:
    84 	  bk = db.get_bookmarks([id])[0]
    83 	  bk = db.get_bookmarks([id])[0]
    85 	  (ids, kw) = apply(zip,db.get_keywords([id]))
    84 	  (ids, kw) = apply(zip,db.get_keywords([id]))
    86 	  kw = kw[1:]
    85 	  kw = kw[1:]
    87 	main(action, bk, kw, db.get_preferences())
    86 	main(action, bk, kw, prefs)
    88 
    87