[z3-checkins] r41922 - z3/deliverance/DeliveranceVHoster/trunk/docs
ianb at codespeak.net
ianb at codespeak.net
Fri Apr 6 00:20:13 CEST 2007
Author: ianb
Date: Fri Apr 6 00:20:11 2007
New Revision: 41922
Added:
z3/deliverance/DeliveranceVHoster/trunk/docs/openplans_hooks.py
- copied, changed from r41921, z3/deliverance/DeliveranceVHoster/trunk/docs/example_init_domain.py
Modified:
z3/deliverance/DeliveranceVHoster/trunk/docs/example_init_domain.py
Log:
Added a more specific openplans example
Modified: z3/deliverance/DeliveranceVHoster/trunk/docs/example_init_domain.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/docs/example_init_domain.py (original)
+++ z3/deliverance/DeliveranceVHoster/trunk/docs/example_init_domain.py Fri Apr 6 00:20:11 2007
@@ -1,7 +1,6 @@
# the init_domain setting points to a file or module (a file like this
# one). It allows you to define a function that will be run on any
-# newly created domain. Here you can put in default settings. This
-# example is what we use for openplans.org
+# newly created domain. Here you can put in default settings.
import re
Copied: z3/deliverance/DeliveranceVHoster/trunk/docs/openplans_hooks.py (from r41921, z3/deliverance/DeliveranceVHoster/trunk/docs/example_init_domain.py)
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/docs/example_init_domain.py (original)
+++ z3/deliverance/DeliveranceVHoster/trunk/docs/openplans_hooks.py Fri Apr 6 00:20:11 2007
@@ -1,9 +1,13 @@
-# the init_domain setting points to a file or module (a file like this
-# one). It allows you to define a function that will be run on any
-# newly created domain. Here you can put in default settings. This
-# example is what we use for openplans.org
+# the init_domain, find_remote_uri, and should_theme_uri settings
+# point to a file or module (a file like this one). It allows you to
+# define a function that will be run on any newly created domain,
+# define how requests are mapped to backend domains, and conditionally
+# theme requests. Here you can put in default settings. This example
+# is what we use for openplans.org
import re
+from paste.deploy.converters import asbool
+from paste.request import path_info_pop
rule_data = """\
<?xml version="1.0" encoding="UTF-8"?>
@@ -13,46 +17,61 @@
</rules>
"""
-
def init_domain(domain_info, app_conf):
+ r"""
+ Initializes an openplans project, based on a domain regular
+ expression (default ``^(.*)\.openplans\.org$`` but you can
+ override with the ``domain_regex`` config setting).
+
+ Also requires a ``default_theme_uri`` setting.
+ """
domain = domain_info.domain
- match = re.search(r'^(.*)\.openplans\.org$', domain, re.I)
+ regex = app_conf.get('domain_regex', r'^(.*)\.openplans\.org$')
+ match = re.search(domain_regex, domain, re.I)
if not match:
# Don't try to set up domains we don't recognize
return
project = match.group(1)
- remote_uri = (
- '%s/VirtualHostBase/http/%s:80/openplans/projects/%s/VirtualHostRoot'
- % (app_conf['zope_location'],
- domain,
- project))
- domain_info.remote_uris = [
+ remote_uris = [
{'path': '',
- 'remote_uri': remote_uri}]
+ 'headers': {'X-Openplans-Project': project}},
+ ]
+ domain_info.remote_uris = remote_uris
domain_info.theme_uri = app_conf['default_theme_uri']
domain_info.set_rule_file(
'rule.xml', rule_data)
- domain_info.additional_request_headers = [
- ('X-Openplans-Project', project),
- ]
-
+
def find_remote_uri(remote_uri, remote_uri_info, environ,
app_conf):
- from paste.request import path_info_pop
+ """
+ Maps request to a remote_uri (when none has been explicitly set).
+
+ You must configure a task_tracker_uri and zope_uri (typically
+ ``http://localhost:X``).
+ """
if remote_uri is not None:
+ # It's already explicitly set
return remote_uri
+ zope_uri = app_conf['zope_uri']
+ task_tracker_uri = app_conf['task_tracker_uri']
+ project = environ['HTTP_X_OPENPLANS_PROJECT']
path_info = environ.get('PATH_INFO', '')
if path_info.startswith('/tasks'):
- remote_uri = 'http://localhost:5000'
+ remote_uri = task_tracker_uri
# Move /tasks to SCRIPT_NAME
path_info_pop(environ)
else:
- remote_uri = 'http://localhost:8080'
+ remote_uri = '%s/VirtualHostBase/http/%s/openplans/projects/%s/VirtualHostRoot' % (
+ zope_uri,
+ environ['HTTP_HOST'],
+ project)
return remote_uri
def should_theme_uri(remote_uri, environ, app_conf):
- try:
- no_theme = int(environ.get('HTTP_X_NO_THEME', '0'))
- except ValueError:
- no_theme = 0
- return not no_theme
+ """
+ This will avoid theming Zope URLs, but only if you have set the
+ configuration ``no_filter_zope = true``
+ """
+ if not asbool(app_conf.get('no_filter_zope')):
+ return True
+ return not remote_uri.startswith(app_conf['zope_uri'])
More information about the z3-checkins
mailing list