# HG changeset patch # User fabien # Date 1064344271 14400 # Node ID 9e7e8b678819ff4a9cc30bb41b9df215094309c2 # Parent 4cb6d9f3d3eb66930c33fc3b10b9608b507d1d0f [svn r1530] Add and browse working. diff -r 4cb6d9f3d3eb -r 9e7e8b678819 .cvsignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.cvsignore Tue Sep 23 15:11:11 2003 -0400 @@ -0,0 +1,2 @@ +*.pyc +*.tmplc diff -r 4cb6d9f3d3eb -r 9e7e8b678819 .htaccess --- a/.htaccess Tue Sep 23 10:26:35 2003 -0400 +++ b/.htaccess Tue Sep 23 15:11:11 2003 -0400 @@ -1,8 +1,9 @@ -AuthType Basic -AuthUserFile /home/fabien/.htpasswd AddHandler cgi-script py Options +ExecCGI DirectoryIndex index.py +AuthType Basic +AuthName Fabien@TZoNE +AuthUserFile /home/fabien/.htpasswd require valid-user diff -r 4cb6d9f3d3eb -r 9e7e8b678819 add.py --- a/add.py Tue Sep 23 10:26:35 2003 -0400 +++ b/add.py Tue Sep 23 15:11:11 2003 -0400 @@ -14,30 +14,17 @@ from htmltmpl import TemplateManager, TemplateProcessor import my_db import time -import bkmark - -def main(msg): - tmpl = TemplateManager().prepare("add.tmpl") - tproc = TemplateProcessor() - tproc.set("msg", msg) +from bkmark import Bookmark -# tproc.set("syntax", user.syntax) -# for syntax in Tester.syntax_name: -# tproc.set("syntax_" + syntax, -# (Tester.syntax_name[user.syntax] == syntax)) -# tproc.set("id", user.id) -# tproc.set("gender", user.gender); -# tproc.set("age", user.age); -# exp = [] -# for key in Tester.keys: -# exp.append({ 'name' : key, -# 'value' : user.experience[key] }); -# tproc.set('Exp', exp); +def main(keywords): + tmpl = TemplateManager().prepare("add_bk.tmpl") + tproc = TemplateProcessor() + tproc.set('Keywords', keywords); print tproc.process(tmpl) if (__name__ == "__main__"): - form = cgi.FieldStorage() - cnx = my_db.connect() - entry = bkmark.get_from_form(form) - qry = entry.add_to_db(cnx) - main(str(qry)) + db = my_db.connect() + kw = db.get_all_keywords()[1:] + kw.sort(lambda l,r: cmp(l[1],r[1])) + kw = map(lambda elem: { 'id' : elem[0], 'keyword' : elem[1] }, kw) + main(kw) diff -r 4cb6d9f3d3eb -r 9e7e8b678819 add_bk.tmpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/add_bk.tmpl Tue Sep 23 15:11:11 2003 -0400 @@ -0,0 +1,24 @@ + + + Add a bookmark + + +

Add a bookmark

+
+
+
+
+
+ + +
+
+ Mots clés: + + + + diff -r 4cb6d9f3d3eb -r 9e7e8b678819 add_result.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/add_result.py Tue Sep 23 15:11:11 2003 -0400 @@ -0,0 +1,54 @@ +#!/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 my_db +import time +from bkmark import Bookmark + +def get_bk_from_form(form): + bk = Bookmark() + bk.url = form['url'].value + bk.name = form['name'].value + bk.desc = form['desc'].value + return bk + +def get_kw_from_form(form): + kw = form.getvalue("kw") + if not isinstance(kw, type([])): + if kw: + kw = [kw] + else: + kw = [] + kw = map(int, kw) + return kw + +def main(bk, kw): + tmpl = TemplateManager().prepare("add_result.tmpl") + tproc = TemplateProcessor() + tproc.set("url", bk.url) + tproc.set("name", bk.name) + tproc.set("added", bk.added) + tproc.set("desc", bk.desc) + tproc.set("Keywords", kw) + print tproc.process(tmpl) + +if (__name__ == "__main__"): + form = cgi.FieldStorage() + db = my_db.connect() + bk = get_bk_from_form(form) + kw = get_kw_from_form(form) + id = db.add_bookmark(bk) + db.update_keywords(id, kw) + kw = map(lambda e: { 'keyword': e[1] }, db.get_keywords(id)[1:]) + main(bk, kw) diff -r 4cb6d9f3d3eb -r 9e7e8b678819 add_result.tmpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/add_result.tmpl Tue Sep 23 15:11:11 2003 -0400 @@ -0,0 +1,33 @@ + + + + + Bookmarker 3 + + +

Bookmarker 3

+

Welcome to bookmarker 3!

+

Bookmark successfully added:

+

+

+

Keywords:

+ + + + diff -r 4cb6d9f3d3eb -r 9e7e8b678819 inc/keywords.tmpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inc/keywords.tmpl Tue Sep 23 15:11:11 2003 -0400 @@ -0,0 +1,6 @@ +
    + +
  • +
    +
+ diff -r 4cb6d9f3d3eb -r 9e7e8b678819 index.py --- a/index.py Tue Sep 23 10:26:35 2003 -0400 +++ b/index.py Tue Sep 23 15:11:11 2003 -0400 @@ -14,27 +14,42 @@ from htmltmpl import TemplateManager, TemplateProcessor import my_db -def main(msg): +def get_selection(form): + kw = form.getvalue("kw") + if not isinstance(kw, type([])): + if kw: + kw = [kw] + else: + kw = [0] + return map(int, kw) + +def set_selection(kw, sel): + res = [] + for key in kw: + chk = key[0] in sel + res.append({'id':key[0], + 'keyword': key[1], + 'checked' : chk}) + return res + +def main(bk, kw): tmpl = TemplateManager().prepare("index.tmpl") tproc = TemplateProcessor() - tproc.set("msg", msg) - -# tproc.set("syntax", user.syntax) -# for syntax in Tester.syntax_name: -# tproc.set("syntax_" + syntax, -# (Tester.syntax_name[user.syntax] == syntax)) -# tproc.set("id", user.id) -# tproc.set("gender", user.gender); -# tproc.set("age", user.age); -# exp = [] -# for key in Tester.keys: -# exp.append({ 'name' : key, -# 'value' : user.experience[key] }); -# tproc.set('Exp', exp); + tproc.set("Bookmarks", bk) + tproc.set("Keywords", kw) print tproc.process(tmpl) if (__name__ == "__main__"): form = cgi.FieldStorage() - cnx = my_db.connect() - qry = cnx.query('SELECT name FROM keywords;') - main(str(qry.getresult())) + db = my_db.connect() + keywords = db.get_all_keywords()[1:] + selection = get_selection(form) + if selection[0] == 0: + exc = map(lambda e: int(e[0]), keywords) + bookmarks = db.select_bookmarks([0], exc) + else: + bookmarks = db.select_bookmarks(selection) + keywords = set_selection(keywords, selection) + bookmarks = db.get_bookmarks(map(lambda x: x[0], bookmarks)) + bookmarks = map(lambda bk: bk.dict(), bookmarks) + main(bookmarks, keywords) diff -r 4cb6d9f3d3eb -r 9e7e8b678819 index.tmpl --- a/index.tmpl Tue Sep 23 10:26:35 2003 -0400 +++ b/index.tmpl Tue Sep 23 15:11:11 2003 -0400 @@ -7,7 +7,26 @@

Bookmarker 3

Welcome to bookmarker 3!

-
+
+ +
+

+
+ +
+
+ Keywords: +
    + +
  • checked + value=""/>
  • +
    +
+
+ +
+