[z3-checkins] r34812 - in z3/deliverance/DeliveranceDemo/trunk: . ddemo ddemo/controllers ddemo/public ddemo/templates ddemo/tests/functional

ianb at codespeak.net ianb at codespeak.net
Mon Nov 20 22:12:30 CET 2006


Author: ianb
Date: Mon Nov 20 22:12:22 2006
New Revision: 34812

Added:
   z3/deliverance/DeliveranceDemo/trunk/ddemo/controllers/index.py   (contents, props changed)
   z3/deliverance/DeliveranceDemo/trunk/ddemo/templates/index.myt
   z3/deliverance/DeliveranceDemo/trunk/ddemo/tests/functional/
   z3/deliverance/DeliveranceDemo/trunk/ddemo/tests/functional/__init__.py   (contents, props changed)
   z3/deliverance/DeliveranceDemo/trunk/ddemo/tests/functional/test_index.py   (contents, props changed)
Removed:
   z3/deliverance/DeliveranceDemo/trunk/ddemo/public/index.html
Modified:
   z3/deliverance/DeliveranceDemo/trunk/ddemo/controllers/__init__.py
   z3/deliverance/DeliveranceDemo/trunk/ddemo/dataprovider.py
   z3/deliverance/DeliveranceDemo/trunk/ddemo/dispatcher.py
   z3/deliverance/DeliveranceDemo/trunk/ddemo/helpers.py
   z3/deliverance/DeliveranceDemo/trunk/ddemo/routing.py
   z3/deliverance/DeliveranceDemo/trunk/ddemo/wsgiapp.py
   z3/deliverance/DeliveranceDemo/trunk/setup.py
Log:
Implemented the dispatching and admin portions

Modified: z3/deliverance/DeliveranceDemo/trunk/ddemo/controllers/__init__.py
==============================================================================
--- z3/deliverance/DeliveranceDemo/trunk/ddemo/controllers/__init__.py	(original)
+++ z3/deliverance/DeliveranceDemo/trunk/ddemo/controllers/__init__.py	Mon Nov 20 22:12:22 2006
@@ -10,4 +10,7 @@
         # Insert any code to be run per request here. The Routes match
         # is under environ['pylons.routes_dict'] should you want to check
         # the action or route vars here
+        di = c.domain_info = environ['ddemo.domain_info']
+        if not di.initialized:
+            di.initialize()
         return WSGIController.__call__(self, environ, start_response)

Added: z3/deliverance/DeliveranceDemo/trunk/ddemo/controllers/index.py
==============================================================================
--- (empty file)
+++ z3/deliverance/DeliveranceDemo/trunk/ddemo/controllers/index.py	Mon Nov 20 22:12:22 2006
@@ -0,0 +1,18 @@
+from ddemo.controllers import *
+import os
+
+class IndexController(BaseController):
+    def index(self):
+        if request.method == 'POST':
+            return self.update()
+        rule_fn = os.path.join(c.domain_info.rule_dir, 'rule.xml')
+        c.rule_text = open(rule_fn, 'rb').read()
+        return render_response('index.myt')
+
+    def update(self):
+        params = request.params
+        di = c.domain_info
+        di.theme_uri = params['theme_uri']
+        di.remote = params['remote']
+        di.set_rule_file('rule.xml', params['rule_xml'])
+        redirect_to()

Modified: z3/deliverance/DeliveranceDemo/trunk/ddemo/dataprovider.py
==============================================================================
--- z3/deliverance/DeliveranceDemo/trunk/ddemo/dataprovider.py	(original)
+++ z3/deliverance/DeliveranceDemo/trunk/ddemo/dataprovider.py	Mon Nov 20 22:12:22 2006
@@ -3,6 +3,28 @@
 
 domain_re = re.compile(r'^[a-z][a-z0-9.\-]+\.[a-z]+$', re.I)
 
+default_rule_xml = '''\
+<?xml version="1.0" encoding="UTF-8"?>
+ 
+<rules xmlns:xi="http://www.w3.org/2001/XInclude" xmlns="http://www.plone.org/deliverance" >
+  <xi:include href="standardrules.xml" />
+
+  <copy theme="//div[@id='container']" content="//*[@id='portal-columns']" />
+</rules>
+'''
+
+default_standardrules = '''\
+<?xml version="1.0" encoding="UTF-8"?>
+<rules xmlns:xi="http://www.w3.org/2001/XInclude" xmlns="http://www.plone.org/deliverance">
+  <prepend theme="//head" content="//head/link" nocontent="ignore" /> 
+  <prepend theme="//head" content="//head/style" nocontent="ignore" /> 
+  <append theme="//head" content="//head/script" nocontent="ignore" />    
+  <append theme="//head" content="//head/meta" nocontent="ignore" />
+  <append-or-replace theme="//head" content="//head/title"
+  nocontent="ignore" />
+</rules>
+'''
+
 class DataProvider(object):
 
     def __init__(self, dir):
@@ -38,9 +60,10 @@
             return self
         if not os.path.exists(self.filename(obj)):
             return None
-        f = open(filename, 'rb')
+        f = open(self.filename(obj), 'rb')
         c = f.read()
         f.close()
+        return c
 
     def __set__(self, obj, value):
         f = open(self.filename(obj), 'wb')
@@ -72,11 +95,18 @@
                     self.static_dir]:
             if not os.path.exists(dir):
                 os.mkdir(dir)
+        for filename, content in [
+            ('rule.xml', default_rule_xml),
+            ('standardrules.xml', default_standardrules)]:
+            filename = os.path.join(self.rule_dir, filename)
+            if not os.path.exists(filename):
+                f = open(filename, 'w')
+                f.write(content)
+                f.close()
 
     @property
     def initialized(self):
-        return os.path.exists(
-            os.path.join(self.dir, 'remote.txt'))
+        return bool(self.remote)
 
     @property
     def rule_dir(self):
@@ -88,3 +118,10 @@
     
     remote = file_property('remote.txt')
     theme_uri = file_property('theme_uri.txt')
+
+    def set_rule_file(self, filename, content):
+        filename = os.path.join(self.rule_dir, filename)
+        f = open(filename, 'wb')
+        f.write(content)
+        f.close()
+        

Modified: z3/deliverance/DeliveranceDemo/trunk/ddemo/dispatcher.py
==============================================================================
--- z3/deliverance/DeliveranceDemo/trunk/ddemo/dispatcher.py	(original)
+++ z3/deliverance/DeliveranceDemo/trunk/ddemo/dispatcher.py	Mon Nov 20 22:12:22 2006
@@ -5,6 +5,7 @@
 from paste.urlparser import StaticURLParser
 from paste.fileapp import FileApp
 from wsgifilter import proxyapp
+from wsgifilter import relocateresponse
 from deliverance.wsgimiddleware import DeliveranceMiddleware
 from ddemo.dataprovider import DataProvider
 
@@ -29,10 +30,13 @@
         domain_info = self.provider.domain(domain)
         environ['ddemo.domain_info'] = domain_info
         path_info = norm_path(environ.get('PATH_INFO', ''))
+        print 'request: %r' % path_info
         if path_info.startswith('/_deliverance'):
             path_info_pop(environ)
             return self.pylons_app(environ, start_response)
-        if not domain_info.initialized:
+        if (not domain_info.initialized
+            or not domain_info.remote
+            or not domain_info.theme_uri):
             new_url = construct_url(
                 environ, with_query_string=False,
                 path_info='/_deliverance')
@@ -46,20 +50,28 @@
             return subapp(environ, start_response)
         static_path = os.path.join(domain_info.static_dir,
                                    path_info.lstrip('/'))
-        if os.path.exists(static_path):
+        static_fn = self.find_file(static_path)
+        if static_fn is not None:
             # Explicit override of a file
-            app = FileApp(static_path)
+            app = FileApp(static_fn)
             return app(environ, start_response)
         app = proxyapp.ForcedProxy(
             remote=domain_info.remote,
             force_host=True)
-        app = proxyapp.RelocateMiddleware(
+        app = relocateresponse.RelocateMiddleware(
             app, old_href=domain_info.remote)
         rule_uri = construct_url(
             environ, with_query_string=False,
-            path_info='/_rules')
+            path_info='/_rules/rule.xml')
         app = DeliveranceMiddleware(
             app,
             theme_uri=domain_info.theme_uri,
             rule_uri=rule_uri)
         return app(environ, start_response)
+
+    def find_file(self, path):
+        if os.path.isdir(path):
+            path = os.path.join(path, 'index.html')
+        if os.path.exists(path):
+            return path
+        return None

Modified: z3/deliverance/DeliveranceDemo/trunk/ddemo/helpers.py
==============================================================================
--- z3/deliverance/DeliveranceDemo/trunk/ddemo/helpers.py	(original)
+++ z3/deliverance/DeliveranceDemo/trunk/ddemo/helpers.py	Mon Nov 20 22:12:22 2006
@@ -4,4 +4,5 @@
 All names available in this module will be available under the Pylons h object.
 """
 from webhelpers import *
+from webhelpers.util import *
 from pylons.helpers import _, log, set_lang, get_lang

Deleted: /z3/deliverance/DeliveranceDemo/trunk/ddemo/public/index.html
==============================================================================
--- /z3/deliverance/DeliveranceDemo/trunk/ddemo/public/index.html	Mon Nov 20 22:12:22 2006
+++ (empty file)
@@ -1,83 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
-   "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-  <title>Pylons Default Page</title>
-  <style>
-    body { background-color: #fff; color: #333; }
-
-    body, p {
-      font-family: verdana, arial, helvetica, sans-serif;
-      font-size:   12px;
-      line-height: 18px;
-    }
-    pre {
-      background-color: #eee;
-      padding: 10px;
-      font-size: 11px;
-      line-height: 13px;
-    }
-
-    a { color: #000; }
-    a:visited { color: #666; }
-    a:hover { color: #fff; background-color:#000; }
-  </style>
-</head>
-<body>
-
-<h1>Welcome to your Pylons Web Application</h1>
-
-<h2>Weren't expecting to see this page?</h2>
-
-<p>The ddemo/public/ directory is searched for static files
- <i>before</i> your controllers are run. Remove this file (ddemo/public/index.html) and edit
-  the routes in <tt>ddemo/config/routing.py</tt> like so:
-  <pre> map.connect('', controller='hello', action='index')</pre>
-</p>
-
-<h2>Getting Started</h2>
-<p>You're now ready to start creating your own web application. Here's what a basic controller looks
-like to print out 'Hello World' and respond to http://127.0.0.1:5000/hello:
-<pre>
-# ddemo/controllers/hello.py
-# Note that the line above is the file you should create and put the following into...
-
-from ddemo.lib.base import *
-
-class HelloController(BaseController):
-    def index(self):
-        return Response('Hello World')
-        
-</pre>
-</p>
-
-<h3>Using a template</h3>
-<p>If you want to call a template and do something a little more complex, here's an example printing out some
-request information from a Myghty template.
-<pre>
-# ddemo/templates/serverinfo.myt
-
-&lt;p>Hi, here's the server environment: &lt;br />
-&lt;% str(request.environ) %>&lt;/p>
-
-&lt;p>
-here's the URL you called: &lt;% h.url_for() %>
-&lt;/p>
-
-&lt;p>
-and here's the name you set: &lt;% c.name %>
-&lt;/p>
-
-</pre>
-
-Then add this to your hello controller class:
-<pre>
-    def serverinfo(self):
-        c.name = 'The Black Knight'
-        return render_response('/serverinfo.myt')
-</pre>
-
-You can now view the page at: <tt>http://127.0.0.1:5000/hello/serverinfo</tt>
-</p>
-</body>
-</html>

Modified: z3/deliverance/DeliveranceDemo/trunk/ddemo/routing.py
==============================================================================
--- z3/deliverance/DeliveranceDemo/trunk/ddemo/routing.py	(original)
+++ z3/deliverance/DeliveranceDemo/trunk/ddemo/routing.py	Mon Nov 20 22:12:22 2006
@@ -6,4 +6,5 @@
     root_path = os.path.dirname(os.path.abspath(__file__))
     map = Mapper(directory=os.path.join(root_path, 'controllers'))
     map.connect(':controller/:action/:id')
+    map.connect('', controller='index')
     return map

Added: z3/deliverance/DeliveranceDemo/trunk/ddemo/templates/index.myt
==============================================================================
--- (empty file)
+++ z3/deliverance/DeliveranceDemo/trunk/ddemo/templates/index.myt	Mon Nov 20 22:12:22 2006
@@ -0,0 +1,28 @@
+<html>
+ <head>
+  <title>Administration for <% c.domain_info.domain_name | h %></title>
+ </head>
+ <body>
+
+<h1>Administration for <% c.domain_info.domain_name | h %></h1>
+
+<p><a href="/">Visit the site</a></p>
+
+<form action="<% h.url_for(controller='index') %>" method="POST">
+  Remote URL:<br>
+   <input type="text" name="remote"
+    value="<% c.domain_info.remote | h %>"
+    style="width: 100%"><br>
+  Theme URL:<br>
+   <input type="text" name="theme_uri"
+    value="<% c.domain_info.theme_uri | h %>"
+    style="width: 100%"><br>
+  Rule:<br>
+   <textarea name="rule_xml" rows=10
+    style="width: 100%"><% c.rule_text | h %></textarea><br>
+  <button type="submit">Save</button>
+</form>
+
+
+ </body>
+</html>

Added: z3/deliverance/DeliveranceDemo/trunk/ddemo/tests/functional/__init__.py
==============================================================================
--- (empty file)
+++ z3/deliverance/DeliveranceDemo/trunk/ddemo/tests/functional/__init__.py	Mon Nov 20 22:12:22 2006
@@ -0,0 +1 @@
+#

Added: z3/deliverance/DeliveranceDemo/trunk/ddemo/tests/functional/test_index.py
==============================================================================
--- (empty file)
+++ z3/deliverance/DeliveranceDemo/trunk/ddemo/tests/functional/test_index.py	Mon Nov 20 22:12:22 2006
@@ -0,0 +1,6 @@
+from ddemo.tests import *
+
+class TestIndexController(TestController):
+    def test_index(self):
+        response = self.app.get(url_for(controller='index'))
+        # Test response...
\ No newline at end of file

Modified: z3/deliverance/DeliveranceDemo/trunk/ddemo/wsgiapp.py
==============================================================================
--- z3/deliverance/DeliveranceDemo/trunk/ddemo/wsgiapp.py	(original)
+++ z3/deliverance/DeliveranceDemo/trunk/ddemo/wsgiapp.py	Mon Nov 20 22:12:22 2006
@@ -6,6 +6,7 @@
 from paste.registry import RegistryManager
 from paste.deploy.config import ConfigMiddleware
 from paste.deploy.converters import asbool
+from paste.recursive import RecursiveMiddleware
 
 import pylons.wsgiapp
 import pylons.config
@@ -49,6 +50,7 @@
     # Build the rest of the stack, see a full template for more details
     if asbool(full_stack):
         app = httpexceptions.make_middleware(app, global_conf)
+        app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware)
     
     app = RegistryManager(app)
     
@@ -56,6 +58,9 @@
     javascripts_app = StaticJavascripts()
     app = Cascade([static_app, javascripts_app, app])
     app = DeliveranceDispatcher(app, app_conf)
-    if asbool(full_stack):
-        app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware)
+    app = RecursiveMiddleware(app)
+    if (asbool(full_stack)
+        and asbool(app_conf.get('debug', global_conf.get('debug')))):
+        from paste.evalexception import EvalException
+        app = EvalException(app)
     return app

Modified: z3/deliverance/DeliveranceDemo/trunk/setup.py
==============================================================================
--- z3/deliverance/DeliveranceDemo/trunk/setup.py	(original)
+++ z3/deliverance/DeliveranceDemo/trunk/setup.py	Mon Nov 20 22:12:22 2006
@@ -2,12 +2,16 @@
 
 setup(
     name='DeliveranceDemo',
-    version="",
-    #description="",
+    version="0.1",
+    description="A demo setup of Deliverance, self-configuring",
     #author="",
     #author_email="",
     #url="",
-    install_requires=["Pylons>=0.9.3"],
+    install_requires=[
+      "Pylons>=0.9.3",
+      'Deliverance',
+      'WSGIFilter',
+      ],
     packages=find_packages(),
     include_package_data=True,
     test_suite = 'nose.collector',
@@ -18,4 +22,4 @@
     [paste.app_install]
     main=paste.script.appinstall:Installer
     """,
-)
\ No newline at end of file
+)


More information about the z3-checkins mailing list