[svn r1547] Add count to keywords. xbelweb
authorfabien
Wed, 24 Sep 2003 17:19:52 -0400
branchxbelweb
changeset 13 7357230539d2
parent 12 800be3836f3b
child 14 cdb4ed8660c5
[svn r1547] Add count to keywords.
TODO
add_result.py
index.py
index.tmpl
lib/my_db.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TODO	Wed Sep 24 17:19:52 2003 -0400
@@ -0,0 +1,10 @@
+* Used SQL sequence instead of the db_sequence table.
+* Add delete bookmark.
+* Add edit/delete/merge keyword.
+* Add CSS.
+* Add better navigational means.
+* Add limit query page or move keywords up.
+* Add Search capabilities.
+* Add default (dynamic?) tree expansion.
+* Add multiuser support.
+* Add XBel Import/Export.
--- a/add_result.py	Wed Sep 24 16:44:09 2003 -0400
+++ b/add_result.py	Wed Sep 24 17:19:52 2003 -0400
@@ -59,7 +59,7 @@
     bk = get_bk_from_form(form)
     kw = get_kw_from_form(form)
     newkw = get_new_kw_from_form(form)
-    (ids, kws) = map(list,apply(zip, db.get_all_keywords()))
+    (ids, kws, cnt) = map(list,apply(zip, db.get_all_keywords()))
     for elem in newkw:
     	if elem in kws:
 		kw.append(ids[kws.index(elem)])
--- a/index.py	Wed Sep 24 16:44:09 2003 -0400
+++ b/index.py	Wed Sep 24 17:19:52 2003 -0400
@@ -31,6 +31,7 @@
 		chk = key[0] in sel
 		res.append({'id':key[0],
 			'keyword': key[1],
+			'count' : key[2],
 			'checked' : chk})
 	res.sort(lambda l,r: cmp(l["keyword"],r["keyword"]))
 	return res
@@ -38,18 +39,21 @@
 def get_curl():
 	return urljoin( 'http://' + environ["HTTP_HOST"] + environ["REQUEST_URI"], 'add.py')
 
-def main(bk, kw, curl):
+def main(bk, kw, curl, total):
     tmpl = TemplateManager().prepare("index.tmpl")
     tproc = TemplateProcessor()
     tproc.set("Bookmarks", bk)
     tproc.set("Keywords", kw)
     tproc.set("curl", curl)
+    tproc.set("total", total)
     print tproc.process(tmpl)
 
 if (__name__ == "__main__"):
     form = cgi.FieldStorage()
     db = my_db.connect()
-    keywords = db.get_all_keywords()[1:]
+    keywords = db.get_all_keywords()
+    total = keywords[0][2]
+    keywords = keywords[1:]
     selection = get_selection(form)
     if selection[0] == 0:
     	exc = map(lambda e: int(e[0]), keywords)
@@ -61,4 +65,4 @@
     	bookmarks = db.get_bookmarks(map(lambda x: x[0], bookmarks))
     bookmarks = map(lambda bk: bk.dict(), bookmarks)
     curl = get_curl();
-    main(bookmarks, keywords, curl)
+    main(bookmarks, keywords, curl, total)
--- a/index.tmpl	Wed Sep 24 16:44:09 2003 -0400
+++ b/index.tmpl	Wed Sep 24 17:19:52 2003 -0400
@@ -10,6 +10,7 @@
     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>.</p>
     
+    <p>Total bookmarks: <TMPL_VAR total></p>
     <dl>
     <TMPL_LOOP Bookmarks>
       <dt>
@@ -27,7 +28,8 @@
 	<TMPL_LOOP Keywords>
 	  <li><input type="checkbox" name="kw"
 	  <TMPL_IF checked>checked</TMPL_IF>
-	  value="<TMPL_VAR id>"/><TMPL_VAR keyword></li>
+	  value="<TMPL_VAR id>"/><TMPL_VAR keyword>
+	  (<TMPL_VAR count>)</li>
 	</TMPL_LOOP>
 	</ul>
 	<button type="reset">Reset</button>
--- a/lib/my_db.py	Wed Sep 24 16:44:09 2003 -0400
+++ b/lib/my_db.py	Wed Sep 24 17:19:52 2003 -0400
@@ -123,8 +123,12 @@
 			""" % (into_id, merge_id))
 		self.remove_keyword(merge_id)
 	def get_all_keywords(self):
-		"""Return a list of pair-elements [id, keyword]."""
-		self.crs.execute("SELECT id, name FROM keywords ORDER BY id;")
+		"""Return a list of triplets [id, keyword, count]."""
+		self.crs.execute("""SELECT k.id, k.name, COUNT(bk.keyword)
+			FROM keywords k, bookmarks_keywords bk
+			WHERE k.id = bk.keyword
+			GROUP BY k.id, k.name
+			ORDER BY k.id;""")
 		return self.crs.fetchall()
 	def select_bookmarks(self, has_kw = [0], except_kw = []):
 	        """