Fleshing out the Task model and related access points

This commit is contained in:
2012-10-19 22:17:03 +01:00
parent 6afe3c7345
commit da2bf07f9f
12 changed files with 156 additions and 4 deletions

30
django_ett/etasks/api.py Normal file
View File

@@ -0,0 +1,30 @@
from tastypie.resources import ModelResource
from tastypie.authentication import ApiKeyAuthentication
from tastypie.authorization import Authorization
from tastypie.api import Api
from .models import Task, TimeEntry
class EtasksAuthorization(Authorization):
def apply_limits(self, request, object_list):
if request and hasattr(request, 'user'):
return object_list.filter(user__pk=request.user.pk)
return object_list.none()
class TaskResource(ModelResource):
class Meta:
queryset = Task.objects.all()
resource_name = 'task'
authentication = ApiKeyAuthentication()
authorization = EtasksAuthorization()
v1_api = Api(api_name='1.0')
v1_api.register(TaskResource())