[svn r1543] Ajout des fonctions d'�ditions.
--- a/add.py Wed Sep 24 14:29:18 2003 -0400
+++ b/add.py Wed Sep 24 15:48:47 2003 -0400
@@ -21,7 +21,9 @@
tproc = TemplateProcessor()
tproc.set('ctitle', title)
tproc.set('curl', url)
- tproc.set('Keywords', keywords);
+ tproc.set('desc', '')
+ tproc.set('bkid', -1)
+ tproc.set('Keywords', keywords)
print tproc.process(tmpl)
if (__name__ == "__main__"):
@@ -34,5 +36,8 @@
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)
+ kw = map(lambda elem: {
+ 'id' : elem[0],
+ 'keyword' : elem[1],
+ 'checked' : 0 }, kw)
main(kw, name, url)
--- a/add.tmpl Wed Sep 24 14:29:18 2003 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
- <title>Bookmarker 3</title>
- </head>
- <body>
- <h1>Bookmarker 3</h1>
- <p>Welcome to bookmarker 3!</p>
- <pre><TMPL_VAR msg></pre>
- </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:
--->
--- a/add_bk.tmpl Wed Sep 24 14:29:18 2003 -0400
+++ b/add_bk.tmpl Wed Sep 24 15:48:47 2003 -0400
@@ -6,19 +6,22 @@
<h1>Add a bookmark</h1>
<form action="add_result.py" method="post" name="add">
<fieldset class="bookmark">
+ <input type="hidden" name="id" value="<TMPL_VAR bkid>"/>
<label>Nom: <input type="text" name="name"
- value="<TMPL_VAR ctitle>"></label><br/>
+ value="<TMPL_VAR ctitle>"/></label><br/>
<label>URL: <input type="text" name="url"
- value="<TMPL_VAR curl>"></label><br/>
+ value="<TMPL_VAR curl>"/></label><br/>
<label for="desc">Description: </label><br/>
- <textarea name="desc" rows="5" cols="40"></textarea>
+ <textarea name="desc" rows="5" cols="40"><TMPL_VAR desc></textarea>
<button type="submit" name="submit">Soumettre</button>
</fieldset>
<fieldset class="keywords">
<legend>Mots clés:</legend>
<ul>
<TMPL_LOOP Keywords>
- <li><input type="checkbox" name="kw" value="<TMPL_VAR id>"/><TMPL_VAR keyword></li>
+ <li><input type="checkbox" name="kw"
+ <TMPL_IF checked>checked</TMPL_IF>
+ value="<TMPL_VAR id>"/><TMPL_VAR keyword></li>
</TMPL_LOOP>
</ul>
<label>New keywords: <input type="text" name="newkw"> (comma separated list)</label>
--- a/add_result.py Wed Sep 24 14:29:18 2003 -0400
+++ b/add_result.py Wed Sep 24 15:48:47 2003 -0400
@@ -18,6 +18,7 @@
def get_bk_from_form(form):
bk = Bookmark()
+ bk.id = int(form['id'].value)
bk.url = form['url'].value
bk.name = form['name'].value
bk.desc = form['desc'].value
@@ -56,13 +57,18 @@
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()))
for elem in newkw:
-# try:
- id = db.add_keyword(elem)
- kw.append(id)
-# except:
-# print '<p class="error">Error inserting keyword "'+elem+'".</p>'
- id = db.add_bookmark(bk)
+ if elem in kws:
+ kw.append(ids[kws.index(elem)])
+ else:
+ id = db.add_keyword(elem)
+ kw.append(id)
+ 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)
--- a/add_result.tmpl Wed Sep 24 14:29:18 2003 -0400
+++ b/add_result.tmpl Wed Sep 24 15:48:47 2003 -0400
@@ -2,16 +2,17 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
- <title>Bookmarker 3</title>
+ <title>Fabien's XBelWeb</title>
</head>
<body>
- <h1>Bookmarker 3</h1>
- <p>Welcome to bookmarker 3!</p>
+ <h1>Fabien's XBelWeb</title>
<p>Bookmark successfully added:</p>
<p><a href="<TMPL_VAR url>"><TMPL_VAR name></a><p>
<p><TMPL_VAR desc></p>
<p>Keywords:</p>
<TMPL_INCLUDE NAME="keywords.tmpl">
+ <hr>
+ <p>Retour à la <a href="index.py">page principale</a></p>
</body>
</html>
<!-- Keep this comment at the end of the file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/edit.py Wed Sep 24 15:48:47 2003 -0400
@@ -0,0 +1,41 @@
+#!/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 main(keywords, bk):
+ tmpl = TemplateManager().prepare("add_bk.tmpl")
+ tproc = TemplateProcessor()
+ tproc.set('ctitle', bk.name)
+ tproc.set('curl', bk.url)
+ tproc.set('desc', bk.desc)
+ tproc.set('bkid', bk.id)
+ tproc.set('Keywords', keywords)
+ print tproc.process(tmpl)
+
+if (__name__ == "__main__"):
+ form = cgi.FieldStorage()
+ id = int(form["id"].value)
+ db = my_db.connect()
+ bk = db.get_bookmarks([id])[0]
+ kw = db.get_all_keywords()[1:]
+ kw.sort(lambda l,r: cmp(l[1],r[1]))
+ (ids, kws) = apply(zip,db.get_keywords(id))
+ kw = map(lambda elem: {
+ 'id' : elem[0],
+ 'keyword' : elem[1],
+ 'checked' : elem[0] in ids }, kw)
+ main(kw, bk)
--- a/index.py Wed Sep 24 14:29:18 2003 -0400
+++ b/index.py Wed Sep 24 15:48:47 2003 -0400
@@ -32,6 +32,7 @@
res.append({'id':key[0],
'keyword': key[1],
'checked' : chk})
+ res.sort(lambda l,r: cmp(l["keyword"],r["keyword"]))
return res
def get_curl():
--- a/index.tmpl Wed Sep 24 14:29:18 2003 -0400
+++ b/index.tmpl Wed Sep 24 15:48:47 2003 -0400
@@ -2,18 +2,21 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
- <title>Bookmarker 3</title>
+ <title>Fabien's XBelWeb</title>
</head>
<body>
- <h1>Bookmarker 3</h1>
- <p>Welcome to bookmarker 3!</p>
+ <h1>Fabien's XBelWeb</h1>
<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>.</p>
<dl>
<TMPL_LOOP Bookmarks>
- <dt><a href="<TMPL_VAR url>"><TMPL_VAR name></a></dt>
+ <dt>
+ <a href="<TMPL_VAR url>"><TMPL_VAR name></a>
+ <a href="edit.py?id=<TMPL_VAR id>">edit<a>
+ <a href="delete.py?id=<TMPL_VAR id>">delete<a>
+ </dt>
<dd><p><TMPL_VAR desc></p></dd>
</TMPL_LOOP>
</ul>
@@ -27,6 +30,7 @@
value="<TMPL_VAR id>"/><TMPL_VAR keyword></li>
</TMPL_LOOP>
</ul>
+ <button type="reset">Reset</button>
</fieldset>
<button type="submit">Refresh</button>
</form>