diff --git a/src/milla/dispatch/routing.py b/src/milla/dispatch/routing.py index 04d78fe..b6828d1 100644 --- a/src/milla/dispatch/routing.py +++ b/src/milla/dispatch/routing.py @@ -11,6 +11,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from milla.dispatch import UnresolvedPath +import functools +import re +import sys +import urllib +import urlparse '''URL router :Created: Mar 13, 2011 @@ -19,11 +25,6 @@ :Updater: $Author$ ''' -from milla.dispatch import UnresolvedPath -import functools -import re -import sys -import urllib class Router(object): '''A dispatcher that maps arbitrary paths to controller callables @@ -164,17 +165,22 @@ class Generator(object): url = Generator(request).generate ''' - def __init__(self, request): + def __init__(self, request, path_only=True): self.request = request + self.path_only = path_only def generate(self, *segments, **vars): '''Combines segments and the application's URL into a new URL ''' - base_url = self.request.application_url path = '/'.join(str(s) for s in segments) if not path.startswith('/'): path = '/' + path + + url = self.request.relative_url(path, to_application=True) + if self.path_only: + split = urlparse.urlsplit(url) + url = split.path if vars: - path += '?' + urllib.urlencode(vars) - return base_url + path + url += '?' + urllib.urlencode(vars) + return url