From bb672fe3c2e2a90fa149ba575e36d45c7a4271f7 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 17 Jan 2009 18:59:53 +0000 Subject: - Allow the ``repoze.bfg.view.static`` helper to be passed a relative ``root_path`` name; it will be considered relative to the file in which it was called. --- repoze/bfg/view.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'repoze/bfg/view.py') diff --git a/repoze/bfg/view.py b/repoze/bfg/view.py index 3b27a8b94..67c664855 100644 --- a/repoze/bfg/view.py +++ b/repoze/bfg/view.py @@ -6,6 +6,7 @@ from repoze.bfg.interfaces import ISecurityPolicy from repoze.bfg.interfaces import IViewPermission from repoze.bfg.interfaces import IView +from repoze.bfg.path import caller_path from repoze.bfg.security import Unauthorized from repoze.bfg.security import Allowed @@ -132,15 +133,20 @@ class static(object): directory may contain subdirectories (recursively); the static view implementation will descend into these directories as necessary based on the components of the URL in order to resolve a - path into a response - - Pass the absolute filesystem path to the directory containing - static files directory to the constructor as the ``root_dir`` - argument. ``cache_max_age`` influences the Expires and Max-Age - response headers returned by the view (default is 3600 seconds or - five minutes). + path into a response. + + You may pass an absolute or relative filesystem path to the + directory containing static files directory to the constructor as + the ``root_dir`` argument. If the path is relative, it will be + considered relative to the directory in which the Python file + which calls ``static`` resides. ``cache_max_age`` influences the + Expires and Max-Age response headers returned by the view (default + is 3600 seconds or five minutes). ``level`` influences how + relative directories are resolved (the number of hops in the call + stack), not used very often. """ - def __init__(self, root_dir, cache_max_age=3600): + def __init__(self, root_dir, cache_max_age=3600, level=2): + root_dir = caller_path(root_dir, level=level) self.app = StaticURLParser(root_dir, cache_max_age=cache_max_age) def __call__(self, context, request): -- cgit v1.2.3