Correct some bugs and make keywords edition with the new action
authorfabien@tzone.org
Sun, 28 Dec 2008 12:24:02 -0500
changeset 58 004a32370ba5
parent 57 31271426f879
child 59 2c5e38748004
Correct some bugs and make keywords edition with the new action mechanic.
add_bk.tmpl
add_result.py
add_result.tmpl
do_edit_kw.py
dynamic.tmpl
edit_kw.py
edit_kw.tmpl
folders.tmpl
import.tmpl
inc/footers.tmpl
inc/headers.tmpl
inc/top.tmpl
index.py
kw_confirm.tmpl
kw_delete.tmpl
kw_merge.tmpl
kw_rename.tmpl
kw_result.py
lib/actions.py
lib/actions/add.py
lib/actions/editkw.py
lib/actions/index.py
lib/dynamic.py
lib/folders.py
lib/templates.py
lib/webutils.py
prefs.tmpl
--- a/add_bk.tmpl	Sat Dec 27 20:23:39 2008 -0500
+++ b/add_bk.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -2,7 +2,7 @@
   <TMPL_INCLUDE NAME="headers.tmpl">
   <body>
     <h1><TMPL_VAR remote_user>'s Edit Bookmark</h1>
-    <form action="?action=add" method="post" name="add">
+    <form action="" method="post" name="add">
       <input type="hidden" name="action" value="add"/>
       <fieldset class="bookmark">
         <input type="hidden" name="id" value="<TMPL_VAR bkid>"/>
--- a/add_result.py	Sat Dec 27 20:23:39 2008 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-#!/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 templates import Template
-import time
-from utils import unique
-import my_db
-from add_confirm import get_bk_from_form, get_new_kw_from_form
-from webutils import load_index
-import os
-
-def add_new_keywords(db, newkw):
-    kw = [0] # Default keyword, so that every bookmarks appears in
-             # the bookmarks_keywords db.
-    (ids, kws) = map(list,apply(zip, db.get_all_keywords()))
-    for elem in unique(newkw):
-    	if elem in kws:
-		kw.append(ids[kws.index(elem)])
-	else:
-		id = db.add_keyword(elem)
-		kw.append(id)
-    return kw
-
-def main(bk, kw, prefs):
-    tmpl = Template("add_result.tmpl", prefs)
-    tmpl.set("url", bk.url)
-    tmpl.set("name", bk.name)
-    tmpl.set("added", bk.added)
-    tmpl.set("desc", bk.desc)
-    tmpl.set("Keywords", kw)
-    print tmpl.process()
-
-if (__name__ == "__main__"):
-    form = cgi.FieldStorage()
-    db = my_db.connect(os.environ["REMOTE_USER"])
-    prefs = db.get_preferences()
-    action = form['action'].value
-    if action == 'cancel':
-      load_index(db, prefs)
-    elif action == 'delete':
-      db.remove_bookmark(int(form['id'].value))
-      load_index(db, prefs)
-    else:
-      bk = get_bk_from_form(form)
-      newkw = get_new_kw_from_form(form)
-      kw = add_new_keywords(db, newkw)
-      if bk.id == -1:
-	id = db.add_bookmark(bk)
-      else:
-	db.update_bookmark(bk)
-	id = bk.id
-      db.update_keywords(id, kw)
-      kw = map(lambda e: { 'keyword': e[1] }, db.get_keywords([id])[1:])
-      main(bk, kw, prefs)
--- a/add_result.tmpl	Sat Dec 27 20:23:39 2008 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
-  <TMPL_INCLUDE NAME="headers.tmpl">
-  <body>
-    <h1><TMPL_VAR remote_user>'s Add Result</h1>
-    <p>Bookmark successfully added:</p>
-    <p><a href="<TMPL_VAR url>"><TMPL_VAR name></a><p>
-    <p><TMPL_VAR desc></p>
-    <p>Keywords:
-    <TMPL_LOOP Keywords>
-      <TMPL_VAR keyword>;
-    </TMPL_LOOP></p>
-    <hr>
-    <p>Back to the <a href="index.py">main page</a></p>
-  </body>
-</html>
-<!-- Keep this comment at the end of the file
-Local variables:
-mode: sgml
-sgml-omittag:t
-sgml-shorttag:t
-sgml-namecase-general:t
-sgml-general-insert-case:lower
-sgml-minimize-attributes:nil
-sgml-always-quote-attributes:t
-sgml-indent-step:2
-sgml-indent-data:nil
-sgml-parent-document:nil
-sgml-exposed-tags:nil
-sgml-local-catalogs:nil
-sgml-local-ecat-files:nil
-End:
-vi: syntax=html
--->
--- a/do_edit_kw.py	Sat Dec 27 20:23:39 2008 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-#!/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 templates import Template
-import my_db
-from bkmark import Bookmark
-from keywords import get_keywords
-import os
-
-def main(action, sel_keywords, keywords, prefs):
-    tmpl = Template("kw_confirm.tmpl", prefs)
-    tmpl.set("confirm_delete", action == 'delete')
-    tmpl.set("confirm_merge", action == 'merge')
-    tmpl.set("confirm_rename", action == 'rename')
-    tmpl.set("action", action)
-    tmpl.set("Selected", sel_keywords)
-    tmpl.set("Keywords", keywords)
-    print tmpl.process()
-
-if (__name__ == "__main__"):
-    form = cgi.FieldStorage()
-    db = my_db.connect(os.environ["REMOTE_USER"])
-    ids = get_keywords(form, 'kw')
-    keywords = map(lambda e: { 'id': e[0], 'keyword': e[1]},
-   	 db.get_all_keywords()[1:])
-    keywords.sort(lambda x, y: cmp(x['keyword'],y['keyword']))
-    sel_keywords = filter(lambda e: e['id'] in ids, keywords)
-    keywords = filter(lambda e: e['id'] not in ids, keywords)
-    action = form['action'].value
-    main(action, sel_keywords, keywords, db.get_preferences())
-
--- a/dynamic.tmpl	Sat Dec 27 20:23:39 2008 -0500
+++ b/dynamic.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -2,7 +2,7 @@
 <html>
   <TMPL_INCLUDE NAME="headers.tmpl">
   <body>
-    <h1><TMPL_VAR remote_user>'s XBelWeb</h1>
+    <TMPL_INCLUDE NAME="top.tmpl">
     <p>Total bookmarks: <TMPL_VAR total></p>
     <form action="?action=index&view=dynamic" method="get" name="keywords">
       <fieldset class="keywords">
--- a/edit_kw.py	Sat Dec 27 20:23:39 2008 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-#!/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 templates import Template
-import my_db
-import time
-import os
-
-def main(keywords, prefs):
-    tmpl = Template("edit_kw.tmpl", prefs)
-    tmpl.set('Keywords', keywords)
-    print tmpl.process()
-
-if (__name__ == "__main__"):
-    form = cgi.FieldStorage()
-    db = my_db.connect(os.environ["REMOTE_USER"])
-    kw = db.get_all_keywords()[1:]
-    kw = map(lambda elem: {
-   	 'id' : elem[0],
-	 'keyword' : elem[1] }, kw)
-    kw.sort(lambda l,r: cmp(l['keyword'],r['keyword']))
-    main(kw, db.get_preferences())
--- a/edit_kw.tmpl	Sat Dec 27 20:23:39 2008 -0500
+++ b/edit_kw.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -2,15 +2,16 @@
   <TMPL_INCLUDE NAME="headers.tmpl">
   <body>
     <h1><TMPL_VAR remote_user>'s Edit Keywords</h1>
-    <form action="do_edit_kw.py" method="get" name="edit">
+    <form action="" method="get" name="edit">
+    	<input type="hidden" name="action" value="keywords"/>
 	<label>Keywords:
 	<select multiple name="kw" size="<TMPL_VAR kw_size>">
 	<TMPL_LOOP Keywords>
 	  <option value="<TMPL_VAR id>"><TMPL_VAR keyword></option>
 	</TMPL_LOOP></select><br/>
-      <button name="action" type="submit" value="merge">Merge</button><br/>
-      <button name="action" type="submit" value="rename">Rename</button><br/>
-      <button name="action" type="submit" value="delete">Delete</button>
+      <button name="step" type="submit" value="merge">Merge</button><br/>
+      <button name="step" type="submit" value="rename">Rename</button><br/>
+      <button name="step" type="submit" value="delete">Delete</button>
     </form>
   </body>
 </html>
--- a/folders.tmpl	Sat Dec 27 20:23:39 2008 -0500
+++ b/folders.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -2,7 +2,7 @@
 <html>
   <TMPL_INCLUDE NAME="headers.tmpl">
   <body>
-    <h1><TMPL_VAR remote_user>'s XBelWeb</h1>
+    <TMPL_INCLUDE "top.tmpl">
     <TMPL_IF folder>
       <p>Parents: 
         <TMPL_LOOP Parents>
--- a/import.tmpl	Sat Dec 27 20:23:39 2008 -0500
+++ b/import.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -3,14 +3,14 @@
   <TMPL_INCLUDE NAME="headers.tmpl">
   <body>
     <h1><TMPL_VAR remote_user>'s Import XBel File</h1>
-    <form enctype="multipart/form-data" action="index.py" name="import" method="post">
+    <form enctype="multipart/form-data" action="index" name="import" method="post">
     <input type="hidden" name="action" value="import"/>
     <input type="hidden" name="step" value="upload"/>
     <label>XBEL file to import: <input type="file" name="xbelfile"/>
     <button name="upload">Upload</button>
     </form>
     <hr>
-    <p>Retour à la <a href="?action=index">page principale</a></p>
+    <p>Retour à la <a href="?action=index">page principale</a></p>
   </body>
 </html>
 <!-- Keep this comment at the end of the file
--- a/inc/footers.tmpl	Sat Dec 27 20:23:39 2008 -0500
+++ b/inc/footers.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -3,7 +3,7 @@
     <a href="?action=keywords">Edit keywords</a>.<br/>
     <a href="?action=prefs">Edit User Preferences</a>.</p>
     <p>Here the <a
-    href="javascript:bk1='<TMPL_VAR curl>?curl='+escape(location.href)+'&ctitle='+escape(document.title);bkwin=window.open(bk1,'bkqm','width=620,height=500,scrollbars=1,resizable=1');bkwin.focus();">Quick
+    href="javascript:bk1='<TMPL_VAR curl>?action=add&curl='+escape(location.href)+'&ctitle='+escape(document.title);bkwin=window.open(bk1,'bkqm','width=620,height=500,scrollbars=1,resizable=1');bkwin.focus();">Quick
     Mark Link</a>.  Put it on your bookmarks (using <tt>&lt;Right-Mouse
     Click&gt; Bookmark this link</tt>) and just select it when you
     want to bookmark your links.</p>
--- a/inc/headers.tmpl	Sat Dec 27 20:23:39 2008 -0500
+++ b/inc/headers.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -3,3 +3,4 @@
   <meta name="generator" content="XBelWeb"/>
   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"
 </head>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inc/top.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -0,0 +1,2 @@
+<h1><TMPL_VAR remote_user>'s XBelWeb</h1>
+<p id="status" class="<TMPL_VAR status>"><TMPL_VAR status_msg></p>
--- a/index.py	Sat Dec 27 20:23:39 2008 -0500
+++ b/index.py	Sun Dec 28 12:24:02 2008 -0500
@@ -10,7 +10,7 @@
 	print "Content-type: text/html; charset=iso-8859-1;"
 	print
 
-import cgitb; cgitb.enable()
+# import cgitb; cgitb.enable()
 import cgi
 import my_db
 from os import environ
--- a/kw_confirm.tmpl	Sat Dec 27 20:23:39 2008 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
-  <TMPL_INCLUDE NAME="headers.tmpl">
-  <body>
-    <h1><TMPL_VAR remote_user>'s Confirmation</h1>
-    <form name="confirmation" method="post" action="kw_result.py">
-      <TMPL_IF confirm_delete>
-        <p>Do you really want to remove those keywords?</p>
-	<p>
-	<TMPL_LOOP Selected>
-	  <input type="hidden" name="id" value="<TMPL_VAR id>"/>
-	  <TMPL_VAR keyword>;
-	</TMPL_LOOP>
-	</p>
-        <button name="action" type="submit"
-              value="<TMPL_VAR action>">Delete</button>
-      </TMPL_IF>
-      <TMPL_IF confirm_merge>
-        <p>Selected keywords:</p>
-	<p>
-	<TMPL_LOOP Selected>
-	  <input type="hidden" name="id" value="<TMPL_VAR id>"/>
-	  <TMPL_VAR keyword>;
-	</TMPL_LOOP>
-	</p>
-	<label>Merge them with:
-	<select name="kw" multiple size="<TMPL_VAR kw_size">
-	<TMPL_LOOP Keywords>
-	  <option value="<TMPL_VAR id>"><TMPL_VAR keyword></option>
-	</TMPL_LOOP></select><br/>
-        <button name="action" type="submit"
-              value="<TMPL_VAR action>">Merge</button><br/>
-	<label><input type="checkbox" name="remove"/> Remove keywords?</label>
-      </TMPL_IF>
-      <TMPL_IF confirm_rename>
-        <p>Rename<br/>
-        <TMPL_LOOP Selected>
-	  <label><em><TMPL_VAR keyword></em> to
-	  <input type="hidden" name="id" value="<TMPL_VAR id>"/>
-	  <input type="text" name="name<TMPL_VAR id>"
-	     value="<TMPL_VAR keyword>"/></label><br/>
-	</TMPL_LOOP>
-        <button name="action" type="submit"
-              value="<TMPL_VAR action>">Rename</button><br/>
-      </TMPL_IF>
-      <button name="action" type="submit" value="cancel">Cancel</button>
-    </form>
-  </body>
-</html>
-<!-- Keep this comment at the end of the file
-Local variables:
-mode: sgml
-sgml-omittag:t
-sgml-shorttag:t
-sgml-namecase-general:t
-sgml-general-insert-case:lower
-sgml-minimize-attributes:nil
-sgml-always-quote-attributes:t
-sgml-indent-step:2
-sgml-indent-data:nil
-sgml-parent-document:nil
-sgml-exposed-tags:nil
-sgml-local-catalogs:nil
-sgml-local-ecat-files:nil
-End:
-vi: syntax=html
--->
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kw_delete.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+  <TMPL_INCLUDE NAME="headers.tmpl">
+  <body>
+    <h1><TMPL_VAR remote_user>'s Confirmation</h1>
+    <form name="confirmation" method="post" action="">
+      <input type="hidden" name="action" value="keywords"/>
+      <p>Do you really want to remove those keywords?</p>
+      <p>
+	<TMPL_LOOP Selected>
+	  <input type="hidden" name="id" value="<TMPL_VAR id>"/>
+	  <TMPL_VAR keyword>;
+	</TMPL_LOOP>
+      </p>
+      <button name="step" type="submit" value="do_delete">Delete</button>
+      <button name="step" type="submit" value="cancel">Cancel</button>
+    </form>
+  </body>
+</html>
+<!-- Keep this comment at the end of the file
+Local variables:
+mode: sgml
+sgml-omittag:t
+sgml-shorttag:t
+sgml-namecase-general:t
+sgml-general-insert-case:lower
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:2
+sgml-indent-data:nil
+sgml-parent-document:nil
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+vi: syntax=html
+-->
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kw_merge.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+  <TMPL_INCLUDE NAME="headers.tmpl">
+  <body>
+    <h1><TMPL_VAR remote_user>'s Confirmation</h1>
+    <form name="confirmation" method="post" action="">
+      <input type="hidden" name="action" value="keywords"/>
+        <p>Selected keywords:
+	<TMPL_LOOP Selected>
+	  <input type="hidden" name="id" value="<TMPL_VAR id>"/>
+	  <TMPL_VAR keyword>;
+	</TMPL_LOOP>
+	</p>
+	<p>
+	<label for="kw">Merge them with:</label>
+	<select name="kw" multiple size="<TMPL_VAR kw_size">
+	<TMPL_LOOP Keywords>
+	  <option value="<TMPL_VAR id>"><TMPL_VAR keyword></option>
+	</TMPL_LOOP></select>
+	</p>
+	<label><input type="checkbox" name="remove"/>Remove keywords?</label>
+        <button name="step" type="submit" value="do_merge">Merge</button>
+        <button name="step" type="submit" value="cancel">Cancel</button>
+    </form>
+  </body>
+</html>
+<!-- Keep this comment at the end of the file
+Local variables:
+mode: sgml
+sgml-omittag:t
+sgml-shorttag:t
+sgml-namecase-general:t
+sgml-general-insert-case:lower
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:2
+sgml-indent-data:nil
+sgml-parent-document:nil
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+vi: syntax=html
+-->
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kw_rename.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+  <TMPL_INCLUDE NAME="headers.tmpl">
+  <body>
+    <h1><TMPL_VAR remote_user>'s Confirmation</h1>
+    <form name="confirmation" method="post" action="">
+      <input type="hidden" name="action" value="keywords"/>
+        <p>Rename<br/>
+        <TMPL_LOOP Selected>
+	  <label><em><TMPL_VAR keyword></em> to
+	  <input type="hidden" name="id" value="<TMPL_VAR id>"/>
+	  <input type="text" name="name<TMPL_VAR id>"
+	     value="<TMPL_VAR keyword>"/></label><br/>
+	</TMPL_LOOP>
+        <button name="step" type="submit" value="do_rename">Rename</button>
+      <button name="step" type="submit" value="cancel">Cancel</button>
+    </form>
+  </body>
+</html>
+<!-- Keep this comment at the end of the file
+Local variables:
+mode: sgml
+sgml-omittag:t
+sgml-shorttag:t
+sgml-namecase-general:t
+sgml-general-insert-case:lower
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:2
+sgml-indent-data:nil
+sgml-parent-document:nil
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+vi: syntax=html
+-->
--- a/kw_result.py	Sat Dec 27 20:23:39 2008 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-#!/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
-import my_db
-from os import environ
-from webutils import load_index
-from keywords import get_keywords
-
-def do_merge(form, db):
-	fromids = get_keywords(form, 'id')
-	toids = get_keywords(form, 'kw')
-	remove_them = form.has_key('remove')
-	if remove_them:
-		lastid = toids.pop()
-	for id in fromids:
-		fromkw = db.get_keyword(id)
-		for dest in toids:
-			tokw = db.get_keyword(dest)
-			print "<em>Adding '%s' into '%s'.</em><br/>" % (fromkw, tokw)
-			db.add_keywords(id, dest) 
-		if remove_them:
-			tokw = db.get_keyword(lastid)
-			print "<em>Merging '%s' into '%s'.</em><br/>" % (fromkw, tokw)
-			db.merge_keywords(id, lastid)
-
-def do_rename(form, db):
-	ids = get_keywords(form, 'id')
-	for id in ids:
-		oldname = db.get_keyword(id)
-		newname = form['name%d' % id].value
-		print "<em>Renaming '%s' into '%s'.</em><br/>" % (oldname, newname)
-		db.update_keyword(id, newname)
- 
-def do_delete(form, db):
-	ids = get_keywords(form, 'id')
-	for id in ids:
-		kw = db.get_keyword(id)
-		print "<em>Removing '%s'.</em><br/>" % kw
-		db.remove_keyword(id)
-
-if (__name__ == "__main__"):
-    form = cgi.FieldStorage()
-    db = my_db.connect(environ["REMOTE_USER"])
-    prefs = db.get_preferences()
-    action = form['action'].value
-    if action == 'merge':
-	do_merge(form, db)
-    elif action == 'rename':
-	do_rename(form, db)
-    elif action == 'delete':
-    	do_delete(form, db)
-    load_index(db, prefs)
--- a/lib/actions.py	Sat Dec 27 20:23:39 2008 -0500
+++ b/lib/actions.py	Sun Dec 28 12:24:02 2008 -0500
@@ -29,4 +29,4 @@
 actions['edit'] = ('edit', 'do_it')
 actions['import'] = ('imp_xbel', 'do_it')
 actions['add'] = ('add', 'do_it')
-actions['confirm'] = ('add', 'do_it')
+actions['keywords'] = ('editkw', 'do_it')
--- a/lib/actions/add.py	Sat Dec 27 20:23:39 2008 -0500
+++ b/lib/actions/add.py	Sun Dec 28 12:24:02 2008 -0500
@@ -40,7 +40,7 @@
       kw = unique(kw) 
       return kw
 
-def edit(db, prefs, form):
+def edit(db, prefs, form, id):
     name = url = ""
     if form.has_key("ctitle"):
         name = form["ctitle"].value
@@ -52,7 +52,7 @@
          'id' : elem[0],
          'keyword' : elem[1],
          'checked' : 0 }, kw)
-    print_edit(keywords, title, url, prefs)
+    print_edit(id, kw, name, url, prefs)
 
 def confirm(step, bk, kw, prefs):
     tmpl = Template("add_confirm.tmpl", prefs)
@@ -70,12 +70,12 @@
     tmpl.set("desc", bk.desc)
     print tmpl.process()
 
-def print_edit(keywords, title, url, prefs):
+def print_edit(id, keywords, title, url, prefs):
     tmpl = Template("add_bk.tmpl", prefs)
     tmpl.set('ctitle', title)
     tmpl.set('curl', url)
     tmpl.set('desc', '')
-    tmpl.set('bkid', -1)
+    tmpl.set('bkid', id)
     tmpl.set('Keywords', keywords)
     print tmpl.process()
 
@@ -94,9 +94,9 @@
 		bk = get_bk_from_form(form)
 		kw = get_unique_keywords(form, db)
 		db.update_bookmark(bk)
-                load_index(db, prefs)
+                load_index(db, prefs, form, "result", "Bookmark update")
         elif step == 'cancel' or (action == 'delete' and id == -1):
-                load_index(db, prefs)
+                load_index(db, prefs, form, "err", "Operation cancel")
         else:
                 if step == 'update':
                         bk = get_bk_from_form(form)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/actions/editkw.py	Sun Dec 28 12:24:02 2008 -0500
@@ -0,0 +1,94 @@
+from keywords import get_keywords
+from webutils import load_index
+from templates import Template
+
+def print_kw(keywords, prefs):
+    tmpl = Template("edit_kw.tmpl", prefs, "", "")
+    tmpl.set('Keywords', keywords)
+    print tmpl.process()
+
+def print_confirm(step, sel_keywords, keywords, prefs):
+    if step == 'delete':
+    	tmpl = Template("kw_delete.tmpl", prefs)
+    elif step == 'merge':
+    	tmpl = Template("kw_merge.tmpl", prefs)
+    elif step == 'rename':
+    	tmpl = Template("kw_rename.tmpl", prefs)
+    tmpl.set("Selected", sel_keywords)
+    tmpl.set("Keywords", keywords)
+    print tmpl.process()
+
+def list_kw(db, prefs):
+    kw = db.get_all_keywords()[1:]
+    kw = map(lambda elem: {
+   	 'id' : elem[0],
+	 'keyword' : elem[1] }, kw)
+    kw.sort(lambda l,r: cmp(l['keyword'],r['keyword']))
+    print_kw(kw, prefs)
+
+def confirm_kw(step, db, prefs, form):
+    ids = get_keywords(form, 'kw')
+    keywords = map(lambda e: { 'id': e[0], 'keyword': e[1]},
+   	 db.get_all_keywords()[1:])
+    keywords.sort(lambda x, y: cmp(x['keyword'],y['keyword']))
+    sel_keywords = filter(lambda e: e['id'] in ids, keywords)
+    keywords = filter(lambda e: e['id'] not in ids, keywords)
+    print_confirm(step, sel_keywords, keywords, prefs)
+
+def do_merge(db, prefs, form):
+	fromids = get_keywords(form, 'id')
+	toids = get_keywords(form, 'kw')
+	remove_them = form.has_key('remove')
+	if remove_them:
+		lastid = toids.pop()
+	status = "result"
+	status_msg = []
+	for id in fromids:
+		fromkw = db.get_keyword(id)
+		for dest in toids:
+			tokw = db.get_keyword(dest)
+			status_msg.append("Adding '%s' into '%s'." % (fromkw, tokw))
+			db.add_keywords(id, dest) 
+		if remove_them:
+			tokw = db.get_keyword(lastid)
+			status_msg.append("Merging '%s' into '%s'." % (fromkw, tokw))
+			db.merge_keywords(id, lastid)
+	load_index(db, prefs, form, status, "<br/>".join(status_msg))
+
+def do_rename(db, prefs, form):
+	ids = get_keywords(form, 'id')
+	status = "result"
+	status_msg = []
+	for id in ids:
+		oldname = db.get_keyword(id)
+		newname = form['name%d' % id].value
+		status_msg.append("Renaming '%s' into '%s'." % (oldname, newname))
+		db.update_keyword(id, newname)
+	load_index(db, prefs, form, status, "<br/>".join(status_msg))
+ 
+def do_delete(db, prefs, form):
+	ids = get_keywords(form, 'id')
+	status = "result"
+	status_msg = []
+	for id in ids:
+		kw = db.get_keyword(id)
+		status_msg.append("Removing '%s'." % kw)
+		db.remove_keyword(id)
+	load_index(db, prefs, form, status, "<br/>".join(status_msg))
+
+def do_it(action, db, prefs, form):
+	step = 'list'
+	if form.has_key('step'):
+		step = form['step'].value
+	if step == 'list':
+		list_kw(db, prefs)
+	elif step == 'cancel':
+		load_index(db, prefs, form, "err", "Operation cancel")
+	elif step == 'do_delete':
+		do_delete(db, prefs, form)
+	elif step == 'do_merge':
+		do_merge(db, prefs, form)
+	elif step == 'do_rename':
+		do_rename(db, prefs, form)
+	else:
+		confirm_kw(step, db, prefs, form)
--- a/lib/actions/index.py	Sat Dec 27 20:23:39 2008 -0500
+++ b/lib/actions/index.py	Sun Dec 28 12:24:02 2008 -0500
@@ -1,4 +1,4 @@
 from webutils import load_index
 
 def do_it(action, db, prefs, form):
-	load_index(db, prefs, form)
+	load_index(db, prefs, form, "msg", "")
--- a/lib/dynamic.py	Sat Dec 27 20:23:39 2008 -0500
+++ b/lib/dynamic.py	Sun Dec 28 12:24:02 2008 -0500
@@ -3,8 +3,8 @@
 from keywords import get_keywords, sort_keywords, set_selection
 from templates import Template
 
-def process_index(bk, kw, pref):
-    tmpl = Template("dynamic.tmpl", pref)
+def process_index(bk, kw, pref, status, status_msg):
+    tmpl = Template("dynamic.tmpl", pref, status, status_msg)
     bk.sort(lambda x,y: cmp(x['name'],y['name']))
     tmpl.set("Bookmarks", bk)
     kw = sort_keywords(kw, pref)
@@ -12,7 +12,7 @@
     tmpl.set("total", len(bk))
     print tmpl.process()
 
-def do_dynamic(db, prefs, form = []):
+def do_dynamic(db, prefs, form, status, status_msg):
     if form:
         selection = get_keywords(form, 'sel')
         exclusion = get_keywords(form, 'exc')
@@ -31,4 +31,4 @@
     if len(bookmarks) > 0:
     	bookmarks = db.get_bookmarks(map(lambda x: x[0], bookmarks))
     bookmarks = map(lambda bk: bk.dict(), bookmarks)
-    process_index(bookmarks, keywords[1:], prefs)
+    process_index(bookmarks, keywords[1:], prefs, status, status_msg)
--- a/lib/folders.py	Sat Dec 27 20:23:39 2008 -0500
+++ b/lib/folders.py	Sun Dec 28 12:24:02 2008 -0500
@@ -23,8 +23,8 @@
 		result = l['count'] - r['count']
 	return -int(result)
 
-def output(prefs, folder, parents, children, bookmarks, keywords):
-    tmpl = Template("folders.tmpl", prefs)
+def output(prefs, folder, parents, children, bookmarks, keywords, status, status_msg):
+    tmpl = Template("folders.tmpl", prefs, status, status_msg)
     tmpl.set('Parents', parents)
     tmpl.set('folder', folder['id'])
     tmpl.set('name', folder['name'])
@@ -37,7 +37,7 @@
     tmpl.set('Keywords', keywords)
     print tmpl.process()
 
-def do_folders(db, prefs, form = None):
+def do_folders(db, prefs, form, status, status_msg):
     folder = 0
     if form:
     	if form.has_key('folder'):
@@ -89,5 +89,5 @@
     if len(bookmarks) <> 0:
    	bookmarks = db.get_bookmarks(map(lambda bk: bk[0], bookmarks))
     	bookmarks = map(lambda bk: bk.dict(), bookmarks)
-    output(prefs, parents.pop(), parents, children, bookmarks, keywords)
+    output(prefs, parents.pop(), parents, children, bookmarks, keywords, status, status_msg)
 
--- a/lib/templates.py	Sat Dec 27 20:23:39 2008 -0500
+++ b/lib/templates.py	Sun Dec 28 12:24:02 2008 -0500
@@ -3,17 +3,25 @@
 from os import environ
 
 def get_curl():
-	return urljoin( 'http://' + environ["HTTP_HOST"] + environ["REQUEST_URI"], 'add.py')
+	url = "http"
+	if environ["HTTPS"] == 'on':
+		url += "s"
+	url += "://" + environ["HTTP_HOST"]
+	uri = environ["REQUEST_URI"]
+	url += uri[:uri.find('?')]
+	return url
 
 class Template:
-	def __init__(self, template, prefs):
+	def __init__(self, template, prefs, status = "msg", status_msg = ""):
 		self.tproc = TemplateProcessor()
 		self.tmpl = TemplateManager().prepare(template)
-    		self.tproc.set("remote_user", prefs["fullname"])
-    		self.tproc.set("kw_size", prefs['keywords_box'])
-    		self.tproc.set("kw_sort", prefs['keywords_sort'])
-    		self.tproc.set("kw_reverse", prefs['keywords_reverse'])
-    		self.tproc.set("curl", get_curl())
+    		self.set("remote_user", prefs["fullname"])
+    		self.set("kw_size", prefs['keywords_box'])
+    		self.set("kw_sort", prefs['keywords_sort'])
+    		self.set("kw_reverse", prefs['keywords_reverse'])
+    		self.set("curl", get_curl())
+		self.set("status", status)
+		self.set("status_msg", status_msg)
 	def set(self, name, variable):
 		self.tproc.set(name, variable)
 	def process(self):
--- a/lib/webutils.py	Sat Dec 27 20:23:39 2008 -0500
+++ b/lib/webutils.py	Sun Dec 28 12:24:02 2008 -0500
@@ -3,15 +3,15 @@
 from dynamic import do_dynamic
 from folders import do_folders
 
-def load_index(db, prefs, form = None):
+def load_index(db, prefs, form, status, status_msg):
     if form:
     	if form.has_key('view'):
     		if form['view'].value == 'folder':
-    			do_folders(db, prefs, form)
+    			do_folders(db, prefs, form, status, status_msg)
 		else:
-    			do_dynamic(db, prefs, form)
+    			do_dynamic(db, prefs, form, status, status_msg)
 		return
     if prefs['default_view'] == 0:
-        do_dynamic(db, prefs, form)
+        do_dynamic(db, prefs, form, status, status_msg)
     else:
-	do_folders(db, prefs, form)
+	do_folders(db, prefs, form, status, status_msg)
--- a/prefs.tmpl	Sat Dec 27 20:23:39 2008 -0500
+++ b/prefs.tmpl	Sun Dec 28 12:24:02 2008 -0500
@@ -31,7 +31,7 @@
 	<button>Submit</button>
     </form>
     <hr/>
-    <a href="index.py">Back to main page</a>
+    <a href="index">Back to main page</a>
 </html>
 <!-- Keep this comment at the end of the file
 Local variables: