#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from django import http
from django.conf.urls.defaults import url
import re
def execute(request, urls, views):
"""
urls [methodName/]param1/param2/.../
methodName default index
"""
def get_method(views, methodName):
try:
return getattr(views, methodName)
except Exception, e:
return None
method = None
params = [e for e in urls.split("/") if e]
params.reverse()
if params:
method = get_method(views, params.pop())
if not method:
method = get_method(views, 'index')
if not method:
raise http.Http404('The requested admin page does not exist.')
return method(request, *params)
def url_(*args,**dic):
regex = args[0]
if regex[0] == "/":
regex = regex[1:]
regex = '^' + regex
regex = regex + '$'
regex = re.sub(":[^/]+",
lambda matchobj: "(?P<%s>[^/]+)" % matchobj.group(0)[1:],
regex)
return url(regex, *args[1:], **dic)
Comments
what does this do?
#
Neat idea, but wouldn't you be better off just using Routes?
#