[svn r1527] Premi�re version. xbelweb
authorfabien
Tue, 23 Sep 2003 09:00:02 -0400
branchxbelweb
changeset 0 a4c49a0c313b
child 1 800536f34f15
[svn r1527] Premi�re version.
add.py
add.tmpl
index.py
index.tmpl
lib/.htaccess
lib/bkmark.py
lib/create_db.sql
lib/my_db.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/add.py	Tue Sep 23 09:00:02 2003 -0400
@@ -0,0 +1,43 @@
+#!/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
+import bkmark
+
+def main(msg):
+    tmpl = TemplateManager().prepare("add.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);
+    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))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/add.tmpl	Tue Sep 23 09:00:02 2003 -0400
@@ -0,0 +1,29 @@
+<!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:
+-->
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/index.py	Tue Sep 23 09:00:02 2003 -0400
@@ -0,0 +1,40 @@
+#!/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
+
+def main(msg):
+    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);
+    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()))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/index.tmpl	Tue Sep 23 09:00:02 2003 -0400
@@ -0,0 +1,29 @@
+<!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:
+-->
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/.htaccess	Tue Sep 23 09:00:02 2003 -0400
@@ -0,0 +1,2 @@
+Order deny,allow
+Deny from all
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/bkmark.py	Tue Sep 23 09:00:02 2003 -0400
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+
+import time
+
+class Bookmark:
+	def __init__(self):
+		self.url = ''
+		self.name = ''
+		self.desc = ''
+		self.added = time.strftime('%Y-%m-%d')
+	def add_to_db(self, cnx):
+		id = cnx.query("""
+			SELECT nextid FROM db_sequence WHERE
+			db_sequence.seq_name = 'bookmarks';
+			""").getresult()[0][0]
+		res = cnx.query("""
+			INSERT INTO bookmarks(id, url, name, ldesc, added)
+			VALUES (%d, '%s', '%s', '%s', '%s');
+			""" % (id, self.url, self.name, self.desc,
+			self.added))
+		cnx.query("""
+			UPDATE db_sequence SET nextid = %d
+			WHERE seq_name = 'bookmarks';
+			""" % (id+1,))
+		return res
+
+def get_from_form(form):
+	bk = Bookmark()
+	bk.url = form["url"].value
+	bk.name = form["name"].value
+	bk.desc = form["desc"].value
+	return bk
+
+def get_from_id(cnx, id):
+	bk = Bookmark()
+	res = cnx.query("""
+		SELECT url, name, ldesc, added
+		FROM bookmarks
+		WHERE id = %d;
+		""" % (id,))
+	res = res.dictresult()[0]
+	bk.url = res['url']
+	bk.name = res['name']
+	bk.desc = res['ldesc']
+	bk.added = res['added']
+	return bk
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/create_db.sql	Tue Sep 23 09:00:02 2003 -0400
@@ -0,0 +1,50 @@
+--
+-- Table structure for table 'bookmark'
+--
+CREATE TABLE bookmarks (
+  id int NOT NULL,
+  url varchar(255) DEFAULT '' NOT NULL,
+  name varchar(255) DEFAULT '' NOT NULL,
+  ldesc varchar(255) DEFAULT '' NOT NULL,
+  added date DEFAULT '1998-01-01' NOT NULL,
+  PRIMARY KEY (id)
+);
+
+--
+-- Table structure for table 'keywords'
+--
+CREATE TABLE keywords (
+  id int DEFAULT '0' NOT NULL,
+  name varchar(30) DEFAULT '' NOT NULL,
+  PRIMARY KEY (id)
+);
+
+--
+-- Default nil keyword
+--
+
+INSERT INTO keywords(id, name) VALUES (0, '--');
+
+--
+-- Cross reference table for linking keywords and bookmarks
+--
+
+CREATE TABLE bookmarks_keywords (
+  bookmark int NOT NULL,
+  keyword int DEFAULT '0' NOT NULL,
+  PRIMARY KEY (bookmark, keyword)
+);
+
+CREATE INDEX bkkw_kw_idx ON bookmarks_keywords (keyword);
+
+--
+-- Table structure for table 'db_sequence'
+--
+CREATE TABLE db_sequence (
+  seq_name varchar(30)    DEFAULT '' NOT NULL,
+  nextid int DEFAULT '0' NOT NULL,
+  PRIMARY KEY (seq_name)
+);
+
+INSERT INTO db_sequence (seq_name, nextid) VALUES ('bookmarks', 0);
+INSERT INTO db_sequence (seq_name, nextid) VALUES ('keywords' , 1);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/my_db.py	Tue Sep 23 09:00:02 2003 -0400
@@ -0,0 +1,12 @@
+#!/usr/bin/python
+
+import pg
+
+host = 'www.tzone.org'
+user = 'php'
+passwd = 'crow'
+database = 'bookmarker3'
+port = 10021
+
+def connect():
+	return pg.connect(database, host, port, None, None, user, passwd);