from django.conf.urls.defaults import patterns as django_patterns
from django.conf.urls.defaults import url
def patterns(*urls):
pages = []
for cls in urls:
if isinstance(cls, type):
inst = cls()
pages.append(url(inst.url, inst.resource, name = inst.name))
else:
#oldstyle resources
pages.append(cls)
return django_patterns(*pages)
class Page(object):
url = r"^$"
def resource(self, request, *args, **kwargs):
if request.method == "GET":
return self.get(request, *args, **kwargs)
if request.method == "POST":
return self.post(request, *args, **kwargs)
@property
def name(self):
return "%s-%s" % (self.__class__.__name__, "page")
Comments
Do you want to make a view in style of RoR?
#
I've experimented with class-based views in one of my projects. The nasty part is when you want to start using third-party or Django's stock decorators on your views while still being able to access individual methods and attributes in your unit tests.
#