From 330dac21c0908b871fc73d9a17efefb7bd1e04be Mon Sep 17 00:00:00 2001 From: ianb Date: Sat, 14 May 2005 23:12:45 +0000 Subject: Added Wareweb, a new framework. Yea for more frameworks\! --- examples/todo_wareweb/__init__.py | 5 ++ examples/todo_wareweb/db.py | 16 ++++++ examples/todo_wareweb/server.conf | 24 +++++++++ examples/todo_wareweb/sitepage.py | 14 ++++++ examples/todo_wareweb/templates/edit_list.pt | 0 examples/todo_wareweb/templates/generic_error.pt | 7 +++ examples/todo_wareweb/templates/index.pt | 22 +++++++++ .../todo_wareweb/templates/standard_template.pt | 31 ++++++++++++ examples/todo_wareweb/templates/view_list.pt | 57 ++++++++++++++++++++++ examples/todo_wareweb/web/__init__.py | 29 +++++++++++ examples/todo_wareweb/web/edit_list.py | 31 ++++++++++++ examples/todo_wareweb/web/index.py | 9 ++++ examples/todo_wareweb/web/static/stylesheet.css | 13 +++++ examples/todo_wareweb/web/view_list.py | 51 +++++++++++++++++++ 14 files changed, 309 insertions(+) create mode 100644 examples/todo_wareweb/__init__.py create mode 100644 examples/todo_wareweb/db.py create mode 100644 examples/todo_wareweb/server.conf create mode 100644 examples/todo_wareweb/sitepage.py create mode 100644 examples/todo_wareweb/templates/edit_list.pt create mode 100644 examples/todo_wareweb/templates/generic_error.pt create mode 100644 examples/todo_wareweb/templates/index.pt create mode 100644 examples/todo_wareweb/templates/standard_template.pt create mode 100644 examples/todo_wareweb/templates/view_list.pt create mode 100644 examples/todo_wareweb/web/__init__.py create mode 100644 examples/todo_wareweb/web/edit_list.py create mode 100644 examples/todo_wareweb/web/index.py create mode 100644 examples/todo_wareweb/web/static/stylesheet.css create mode 100644 examples/todo_wareweb/web/view_list.py (limited to 'examples') diff --git a/examples/todo_wareweb/__init__.py b/examples/todo_wareweb/__init__.py new file mode 100644 index 0000000..0454673 --- /dev/null +++ b/examples/todo_wareweb/__init__.py @@ -0,0 +1,5 @@ +from paste.util.thirdparty import add_package + +add_package('ZopePageTemplates') +add_package('Component') +add_package('ZPTKit') diff --git a/examples/todo_wareweb/db.py b/examples/todo_wareweb/db.py new file mode 100644 index 0000000..174f0f5 --- /dev/null +++ b/examples/todo_wareweb/db.py @@ -0,0 +1,16 @@ +from sqlobject import * + +class TodoList(SQLObject): + + description = StringCol(notNull=True) + items = MultipleJoin('TodoItem') + +class TodoItem(SQLObject): + + todo_list = ForeignKey('TodoList') + description = StringCol(notNull=True) + done = BoolCol(notNull=True, default=False) + +def check_db(): + for soClass in (TodoList, TodoItem): + soClass.createTable(ifNotExists=True) diff --git a/examples/todo_wareweb/server.conf b/examples/todo_wareweb/server.conf new file mode 100644 index 0000000..70d1b49 --- /dev/null +++ b/examples/todo_wareweb/server.conf @@ -0,0 +1,24 @@ +# -*- python -*- Note: this file is in Python syntax + +import os + +app_name = 'todo_wareweb' +publish_dir = os.path.join(os.path.dirname(__file__), 'web') +sys_path = [os.path.dirname(os.path.dirname(__file__))] + +database = 'sqlite:%s/data.db' % os.path.dirname(__file__) +root_path = os.path.dirname(__file__) + +## Server options: + +verbose = True +# The name of the server-type to start: +server = 'wsgiutils' +# If true, files will be regularly polled and the server restarted +# if files are modified: +reload = True +# If true, tracebacks will be shown in the browser: +debug = True +lint = True +session_type = 'memory' +show_exceptions_in_error_log = False diff --git a/examples/todo_wareweb/sitepage.py b/examples/todo_wareweb/sitepage.py new file mode 100644 index 0000000..52af53c --- /dev/null +++ b/examples/todo_wareweb/sitepage.py @@ -0,0 +1,14 @@ +from paste.wareweb import Servlet, Notify +from ZPTKit.zptwareweb import ZPTComponent + +class SitePage(Servlet): + + zpt = ZPTComponent() + message = Notify() + + def awake(self): + self.app_static_url = self.app_url + '/static' + super(SitePage, self).awake() + + def title__get(self): + return self.options.get('title', super(SitePage, self).title) diff --git a/examples/todo_wareweb/templates/edit_list.pt b/examples/todo_wareweb/templates/edit_list.pt new file mode 100644 index 0000000..e69de29 diff --git a/examples/todo_wareweb/templates/generic_error.pt b/examples/todo_wareweb/templates/generic_error.pt new file mode 100644 index 0000000..7b32820 --- /dev/null +++ b/examples/todo_wareweb/templates/generic_error.pt @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/examples/todo_wareweb/templates/index.pt b/examples/todo_wareweb/templates/index.pt new file mode 100644 index 0000000..704fca8 --- /dev/null +++ b/examples/todo_wareweb/templates/index.pt @@ -0,0 +1,22 @@ + + + + + +

+ There are no lists to display +

+ +
+ Create a new list:
+ + + + +
+
+ diff --git a/examples/todo_wareweb/templates/standard_template.pt b/examples/todo_wareweb/templates/standard_template.pt new file mode 100644 index 0000000..0abe2dd --- /dev/null +++ b/examples/todo_wareweb/templates/standard_template.pt @@ -0,0 +1,31 @@ + + + + +title + + + + + + + +

+ +
+ [This is where the notification messages go] +
+ +
+ +[This page has not customized its "body" slot] + +
+ + + +
diff --git a/examples/todo_wareweb/templates/view_list.pt b/examples/todo_wareweb/templates/view_list.pt new file mode 100644 index 0000000..5ba99c8 --- /dev/null +++ b/examples/todo_wareweb/templates/view_list.pt @@ -0,0 +1,57 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + +
Done?Description
+ + + + [delete]
No items to display
+ + +
+ +
+ +Add item:
+
+ +
+ +
+ + +
+ +
+ 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) + -- cgit v1.2.1