Commits

Anonymous committed 2d2a81f

Proof of concept idea to handle multiple apps: adding a cherrypy.url() function and a is_app_root class attribute for apps

Comments (0)

Files changed (2)

cherrypy/__init__.py

 __version__ = '2.2.0-beta'
 
 import datetime
+import os.path
 import sys
 import types
 
     
     logfunc(msg, context, severity)
 
+def url(u):
+    return request.app_path + u

cherrypy/_cphttptools.py

         objectTrail = _cputil.get_object_trail(objectpath)
         names = [name for name, candidate in objectTrail]
         
+        # Try to get app_path:
+        current_objectpath = objectpath
+        for i in xrange(len(objectTrail) - 1, -1, -1):
+            name, candidate = objectTrail[i]
+            if getattr(candidate, 'is_app_root', False):
+                cherrypy.request.app_path = current_objectpath
+                break
+            current_objectpath = os.path.dirname(current_objectpath)
+
         # Try successive objects (reverse order)
         mounted_app_roots = cherrypy.tree.mount_points.values()
         for i in xrange(len(objectTrail) - 1, -1, -1):