Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

Commit

Permalink
Enable the Resource class to be initialized an called when the class …
Browse files Browse the repository at this point in the history
…is called

This allows for using import strings in urlconf

url(r'^$', 'myapp.resources.RootResource'),
...
  • Loading branch information
bruth committed Mar 6, 2012
1 parent 6e0bd48 commit ba8ba88
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion restlib2/resources.py
Expand Up @@ -3,7 +3,7 @@
from calendar import timegm
from datetime import datetime, timedelta
from django.conf import settings
from django.http import HttpResponse
from django.http import HttpResponse, HttpRequest
from django.utils.http import http_date, parse_http_date
from http import codes, methods

Expand Down Expand Up @@ -59,6 +59,15 @@ def __new__(cls, name, bases, attrs):

return new_cls

def __call__(cls, *args, **kwargs):
"""Tests to see if the first argument is an HttpRequest object, creates
an instance, and calls it with the arguments.
"""
if args and isinstance(args[0], HttpRequest):
instance = super(ResourceMetaclass, cls).__call__()
return instance.__call__(*args, **kwargs)
return super(ResourceMetaclass, cls).__call__(*args, **kwargs)


# ## Resource
# Comprehensive ``Resource`` class which implements sensible request
Expand Down

0 comments on commit ba8ba88

Please sign in to comment.