mirror of
https://github.com/nikdoof/django-ett.git
synced 2025-12-19 12:49:22 +00:00
Fleshing out the Task model and related access points
This commit is contained in:
30
django_ett/etasks/api.py
Normal file
30
django_ett/etasks/api.py
Normal 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())
|
||||
Reference in New Issue
Block a user