summaryrefslogtreecommitdiff
path: root/examples/todo_wareweb/web
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-05-14 23:12:45 +0000
committerianb <devnull@localhost>2005-05-14 23:12:45 +0000
commit330dac21c0908b871fc73d9a17efefb7bd1e04be (patch)
treea30f8371508bf8ff03d8a7ecfa2e28ba9b0dfd41 /examples/todo_wareweb/web
parentc5b9dee9b6ce25ff35a1a06858be781d07de294f (diff)
downloadpaste-330dac21c0908b871fc73d9a17efefb7bd1e04be.tar.gz
Added Wareweb, a new framework. Yea for more frameworks\!
Diffstat (limited to 'examples/todo_wareweb/web')
-rw-r--r--examples/todo_wareweb/web/__init__.py29
-rw-r--r--examples/todo_wareweb/web/edit_list.py31
-rw-r--r--examples/todo_wareweb/web/index.py9
-rw-r--r--examples/todo_wareweb/web/static/stylesheet.css13
-rw-r--r--examples/todo_wareweb/web/view_list.py51
5 files changed, 133 insertions, 0 deletions
diff --git a/examples/todo_wareweb/web/__init__.py b/examples/todo_wareweb/web/__init__.py
new file mode 100644
index 0000000..0fca385
--- /dev/null
+++ b/examples/todo_wareweb/web/__init__.py
@@ -0,0 +1,29 @@
+from paste.util import thirdparty
+thirdparty.add_package('sqlobject')
+import sqlobject
+from todo_wareweb import db
+
+conns = {}
+
+def urlparser_hook(environ):
+ if not environ.has_key('todo_wareweb.base_url'):
+ environ['todo_wareweb.base_url'] = environ['SCRIPT_NAME']
+
+def urlparser_wrap(environ, start_response, app):
+ db_uri = environ['paste.config']['database']
+ first_conn = False
+ if db_uri in conns:
+ conn = conns[db_uri]
+ else:
+ first_conn = True
+ conns[db_uri] = conn = sqlobject.connectionForURI(db_uri)
+ sqlobject.sqlhub.threadConnection = conn
+ if first_conn:
+ db.check_db()
+ # @@: This doesn't allow for using database connections during
+ # the application iterator
+ try:
+ return app(environ, start_response)
+ finally:
+ sqlobject.sqlhub.threadConnection = None
+
diff --git a/examples/todo_wareweb/web/edit_list.py b/examples/todo_wareweb/web/edit_list.py
new file mode 100644
index 0000000..0b79339
--- /dev/null
+++ b/examples/todo_wareweb/web/edit_list.py
@@ -0,0 +1,31 @@
+from todo_wareweb.sitepage import SitePage
+from todo_wareweb.db import *
+from paste.wareweb import ActionDispatch, public
+
+class edit_list(SitePage):
+
+ dispatch = ActionDispatch()
+
+ def setup(self):
+ self.list_id = self.fields.id
+ if self.list_id != 'new':
+ self.list = TodoList.get(int(self.list_id))
+ self.options.title = 'Edit list '
+
+ @public
+ def save(self):
+ desc = self.fields.description
+ if self.list_id == 'new':
+ self.list = TodoList(description=desc)
+ self.message.write('List created')
+ else:
+ self.list.description = desc
+ self.message.write('List updated')
+ self.redirect('view_list', id=self.list.id)
+
+ @public
+ def destroy(self):
+ desc = self.list.description
+ self.list.destroySelf()
+ self.message.write('List %s deleted' % desc)
+ self.redirect('./')
diff --git a/examples/todo_wareweb/web/index.py b/examples/todo_wareweb/web/index.py
new file mode 100644
index 0000000..b5cbaf1
--- /dev/null
+++ b/examples/todo_wareweb/web/index.py
@@ -0,0 +1,9 @@
+from todo_wareweb.sitepage import SitePage
+from todo_wareweb.db import *
+
+class index(SitePage):
+
+ def setup(self):
+ self.options.title = 'List of Lists'
+ self.options.lists = list(TodoList.select())
+
diff --git a/examples/todo_wareweb/web/static/stylesheet.css b/examples/todo_wareweb/web/static/stylesheet.css
new file mode 100644
index 0000000..d70e9ec
--- /dev/null
+++ b/examples/todo_wareweb/web/static/stylesheet.css
@@ -0,0 +1,13 @@
+body {
+ font-family: Helvetica, Arial, sans-serif;
+}
+
+pre {
+ overflow: auto;
+}
+
+div.notifyMessage {
+ border: 2px solid black;
+ background-color: #007700;
+ color: #ffffff;
+}
diff --git a/examples/todo_wareweb/web/view_list.py b/examples/todo_wareweb/web/view_list.py
new file mode 100644
index 0000000..99750c2
--- /dev/null
+++ b/examples/todo_wareweb/web/view_list.py
@@ -0,0 +1,51 @@
+from todo_wareweb.sitepage import SitePage
+from todo_wareweb.db import *
+from paste.wareweb import ActionDispatch, public
+
+class view_list(SitePage):
+
+ dispatch = ActionDispatch()
+
+ def setup(self):
+ self.options.list = TodoList.get(int(self.fields.id))
+ self.options.list_items = list(self.options.list.items)
+ self.options.title = 'List: %s' % self.options.list.description
+
+ @public
+ def check(self):
+ for item in self.options.list.items:
+ checked = self.fields.get('item_%s' % item.id, False)
+ if not checked and item.done:
+ self.message.write('Item %s marked not done'
+ % item.description)
+ item.done = False
+ if checked and not item.done:
+ self.message.write('Item %s marked done'
+ % item.description)
+ item.done = True
+ self.redirect('view_list', id=self.options.list.id)
+
+ @public
+ def add(self):
+ desc = self.fields.description
+ if not desc:
+ self.message.write('You must give a description')
+ else:
+ TodoItem(todo_list=self.options.list,
+ description=desc)
+ self.message.write('Item added')
+ self.redirect(
+ 'view_list', id=self.options.list.id)
+
+ @public
+ def destroy(self):
+ id = int(self.fields.item_id)
+ item = TodoItem.get(id)
+ assert item.todo_list.id == self.options.list.id, (
+ "You are trying to delete %s, which does not "
+ "belong to the list %s" % (item, self.options.list))
+ desc = item.description
+ item.destroySelf()
+ self.message.write("Item %s removed" % desc)
+ self.redirect('view_list', id=self.options.list.id)
+