[svn r1560] Add import functionality and correct a bug in the merge_kw. xbelweb
authorfabien
Sat, 27 Sep 2003 03:17:30 -0400
branchxbelweb
changeset 26 17b0cd274530
parent 25 777bcb36f7be
child 27 212f1dc25b67
[svn r1560] Add import functionality and correct a bug in the merge_kw.
TODO
do_edit_kw.py
do_import.py
import.py
import.tmpl
import.tmplc
index.tmpl
lib/create_db.sql
lib/my_db.py
lib/xbelimp.py
--- a/TODO	Sat Sep 27 01:44:43 2003 -0400
+++ b/TODO	Sat Sep 27 03:17:30 2003 -0400
@@ -4,8 +4,10 @@
 * Add Search capabilities.
 * Add better navigation.
 * Add default (dynamic?) tree expansion.
-* Add XBel Import/Export.
+* Add XBel Export.
 * Add support for icons.
 * Add modified time.
 * Add access/check time.
 * Add user session support.
+* Better unicode handling.
+* "add keyword to selection" function.
--- a/do_edit_kw.py	Sat Sep 27 01:44:43 2003 -0400
+++ b/do_edit_kw.py	Sat Sep 27 03:17:30 2003 -0400
@@ -17,7 +17,7 @@
 from bkmark import Bookmark
 import os
 
-def main(action, id, kwname, merge, mergename):
+def main(action, id, kwname, name, merge, mergename):
     tmpl = TemplateManager().prepare("kw_confirm.tmpl")
     tproc = TemplateProcessor()
     tproc.set("pagetitle", os.environ["REMOTE_USER"]+"'s XBELWeb Confirmation")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/do_import.py	Sat Sep 27 03:17:30 2003 -0400
@@ -0,0 +1,28 @@
+#!/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, TemplateProcessor
+import time
+from utils import unique
+import my_db
+from index import load_index
+import os
+from xbelimp import parse_xbel, import_bookmarks
+
+if (__name__ == "__main__"):
+    form = cgi.FieldStorage()
+    db = my_db.connect(os.environ["REMOTE_USER"])
+    file = form["xbelfile"].file
+    bms = parse_xbel(file)
+    import_bookmarks(db, bms)
+    load_index(db)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/import.py	Sat Sep 27 03:17:30 2003 -0400
@@ -0,0 +1,24 @@
+#!/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, TemplateProcessor
+import os
+
+def main():
+    tmpl = TemplateManager().prepare("import.tmpl")
+    tproc = TemplateProcessor()
+    tproc.set("pagetitle", os.environ["REMOTE_USER"]+"'s XBELWeb Import File")
+    print tproc.process(tmpl)
+
+if (__name__ == "__main__"):
+    main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/import.tmpl	Sat Sep 27 03:17:30 2003 -0400
@@ -0,0 +1,31 @@
+<!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 pagetitle></h1>
+    <form enctype="multipart/form-data" action="do_import.py" name="import" method="post">
+    <label>XBEL file to import: <input type="file" name="xbelfile"/>
+    <button name="upload">Upload</button>
+    </form>
+    <hr>
+    <p>Retour à la <a href="index.py">page principale</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
+-->
Binary file import.tmplc has changed
--- a/index.tmpl	Sat Sep 27 01:44:43 2003 -0400
+++ b/index.tmpl	Sat Sep 27 03:17:30 2003 -0400
@@ -28,7 +28,8 @@
     </TMPL_LOOP>
     </ul>
     <hr/>
-    <p><a href="add.py">Add new bookmark.</a></p>
+    <p><a href="add.py">Add new bookmark</a>.<br/>
+    <a href="import.py">Import a XBEL file</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
     Mark Link</a>.  Put it on your bookmarks (using <tt>&lt;Right-Mouse
--- a/lib/create_db.sql	Sat Sep 27 01:44:43 2003 -0400
+++ b/lib/create_db.sql	Sat Sep 27 03:17:30 2003 -0400
@@ -14,9 +14,9 @@
 CREATE TABLE bookmarks (
   id int NOT NULL,
   userid int NOT NULL,
-  url varchar(255) DEFAULT '' NOT NULL,
-  name varchar(255) DEFAULT '' NOT NULL,
-  ldesc varchar(255) DEFAULT '' NOT NULL,
+  url varchar(1023) DEFAULT '' NOT NULL,
+  name varchar(1023) DEFAULT '' NOT NULL,
+  ldesc varchar(1023) DEFAULT '' NOT NULL,
   added date DEFAULT '1998-01-01' NOT NULL,
   PRIMARY KEY (id, userid)
 );
@@ -29,7 +29,7 @@
 CREATE TABLE keywords (
   id int DEFAULT '0' NOT NULL,
   userid int DEFAULT '0' NOT NULL,
-  name varchar(30) DEFAULT '' NOT NULL,
+  name varchar(255) DEFAULT '' NOT NULL,
   PRIMARY KEY (id, userid)
 );
 
--- a/lib/my_db.py	Sat Sep 27 01:44:43 2003 -0400
+++ b/lib/my_db.py	Sat Sep 27 03:17:30 2003 -0400
@@ -167,10 +167,10 @@
 			AND userid = %d
 			AND bookmark NOT IN 
 			  (SELECT bookmark FROM bookmarks_keywords
-			  WHERE userid = %d AND keyword = %d ))
+			  WHERE userid = %d AND keyword = %d )
 			;
 			""" % (into_id, merge_id, self.userid,
-			self.userid, merge_id))
+			self.userid, into_id))
 		self.remove_keyword(merge_id)
 	def get_all_keywords(self):
 		"""Return a list of doublets [id, keyword, count]."""
--- a/lib/xbelimp.py	Sat Sep 27 01:44:43 2003 -0400
+++ b/lib/xbelimp.py	Sat Sep 27 03:17:30 2003 -0400
@@ -4,7 +4,7 @@
 from xml.sax import saxexts
 import bkmark
 
-def import_xbel(xbelfile):
+def parse_xbel(xbelfile):
     xbel_handler = XBELHandler()
     p=saxexts.XMLParserFactory.make_parser("xml.sax.drivers.drv_xmlproc")
     p.setDocumentHandler( xbel_handler )
@@ -18,27 +18,34 @@
 	_keywords = {}
 	for elem in db.get_all_keywords():
 		_keywords[elem[1]] = elem[0]
+	#print "<body>"
+	#print "<ol>"
 	for child in bms.folders:
 		if isinstance(child, bookmark.Bookmark):
 			import_bookmark(db, child)
 		else:
 			import_folder(db, child)
+	#print "</ol>"
 
 def import_folder(db, folder, keywords = []):
 	global _keywords
 	kw = folder.title.strip().encode('utf-8')
+	#print "<li>" + kw
 	if _keywords.has_key(kw):
 		id = _keywords[kw]
+		#print " [%d]" % (id,)
 	else:
-		#id = db.add_keyword(kw)
-		print "add keyword '" +  kw + "'" 
-		id = len(_keywords)+100
+		id = db.add_keyword(kw)
+		id = len(_keywords)
+		#print " [%d] (added)" % (id,)
 		_keywords[kw] = id
+	#print "<ol>"
 	for child in folder.children:
 		if isinstance(child, bookmark.Bookmark):
 			import_bookmark(db, child, keywords+[id])
 		else:
 			import_folder(db, child, keywords+[id])
+	#print "</ol></li>"
 
 def import_bookmark(db, bookmark, keywords = []):
 	bk = bkmark.Bookmark()
@@ -46,8 +53,8 @@
 	bk.url = bookmark.href.encode('utf-8')
 	if hasattr(bookmark, 'desc'):
 		bk.desc = bookmark.desc.encode('utf-8')
-	print "add bookmark '" + bk.name + "'",
-	# id = db.add_bookmark(bk)
-	print " with keywords '" + ','.join(map(str,keywords)) + "'"
-	# db.update_keywords(id, keywords)
+	id = db.add_bookmark(bk)
+	#print "<li>add bookmark '" + bk.name + "' [%d]" % (id,)
+	#print " with keywords '" + ','.join(map(str,keywords)) + "'</li>"
+	db.update_keywords(id, keywords)