You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
862 B

3 years ago
3 years ago
  1. from rest_framework import generics
  2. from rest_framework.permissions import IsAuthenticated
  3. from ..models import Project
  4. from ..permissions import IsInProjectReadOnlyOrAdmin
  5. from ..serializers import ProjectPolymorphicSerializer, ProjectSerializer
  6. class ProjectList(generics.ListCreateAPIView):
  7. serializer_class = ProjectPolymorphicSerializer
  8. pagination_class = None
  9. permission_classes = [IsAuthenticated & IsInProjectReadOnlyOrAdmin]
  10. def get_queryset(self):
  11. return self.request.user.projects
  12. def perform_create(self, serializer):
  13. serializer.save(users=[self.request.user])
  14. class ProjectDetail(generics.RetrieveUpdateDestroyAPIView):
  15. queryset = Project.objects.all()
  16. serializer_class = ProjectSerializer
  17. lookup_url_kwarg = 'project_id'
  18. permission_classes = [IsAuthenticated & IsInProjectReadOnlyOrAdmin]