Skip to content

Instantly share code, notes, and snippets.

@pilt
Created December 14, 2012 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pilt/4286231 to your computer and use it in GitHub Desktop.
Save pilt/4286231 to your computer and use it in GitHub Desktop.
from memsite.base.api.authorization import MemAuthorization
class DeviceAuthorization(MemAuthorization):
def apply_limits(self, request, object_list):
if request.user.is_authenticated():
return self.apply_user_profile_limits(request, object_list)
return object_list.none()
class DeviceResource(MemModelResource):
class Meta(MemModelResource.Meta):
queryset = Device.objects.all()
fields = ("uuid", "created", "token", "os")
resource_name = "devices"
authorization = DeviceAuthorization()
detail_allowed_methods = ["delete"]
list_allowed_methods = ["post"]
def obj_create(self, bundle, request=None, **kwargs):
new_device = Device.objects.create(
user_profile=request.user.profile,
token=bundle.data["token"],
os=bundle.data["os"]
)
bundle.obj = new_device
return bundle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment