Created
December 14, 2012 15:23
-
-
Save pilt/4286231 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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