On 7/3/06, Ryan Mack <[EMAIL PROTECTED]> wrote:
> I've been working on a bit of middleware that delegates view processing to a
> callable class instead of a function, and find myself going back and forth
> over an implementation detail.
I think you may be overengineering a bit. Django's views can be any
callable object -- not just functions -- so you can pass callable
classes to them. There's no need to use a custom middleware, and
there's no need to use decorators.
In your views.py:
class MethodDelegator(object):
"A generic view class that delegates by request method."
def __call__(self, request, *args, **kwargs):
if request.method == 'GET':
return self.GET(request, *args, **kwargs)
if request.method == 'POST':
return self.POST(request, *args, **kwargs)
# ...
class MyMethodDelegator(object):
"My particular view class that does particular things for my app."
def GET(self, request):
return render_to_response(...)
my_delegator = MyMethodDelegator()
And in your urls.py:
(r'^somepage/$', 'views.my_delegator'),
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---