コード例 #1
0
ファイル: views.py プロジェクト: overture-stack/enrolment
    def retrieve(self, request, pk=None):
        """
        Return for admin,
        return for owner,
        return for user that is invited,
        404 everyone else
        """
        queryset = Projects.objects.all()

        user = self.request.user
        project = get_object_or_404(queryset, pk=pk)

        if user.is_superuser:
            serializer = ProjectSerializer(project)
            return Response(serializer.data)

        if user == project.user:
            serializer = ProjectSerializer(project)
            return Response(serializer.data)

        # Special case for invited user's
        user_invite_for_project = ProjectUsers.objects.filter(
            daco_email=user.email, project=pk)
        is_user_invited = len(user_invite_for_project) > 0
        if is_user_invited:
            serializer = ProjectSerializer(project)
            return Response(serializer.data)

        # Otherwise return 404
        return Response(status=status.HTTP_404_NOT_FOUND)
コード例 #2
0
 def put(self, request, pk):
     project = self.get_object(pk)
     serializer = ProjectSerializer(project, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #3
0
ファイル: views.py プロジェクト: Aiganymus/django2019
 def put(self, request, pk):
     project = self.get_object(pk)
     serializer = ProjectSerializer(instance=project, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors)
コード例 #4
0
 def put(self, request, pk):
     project = get_object_or_404(Project, id=pk)
     if project.creator == request.user:
         serializer = ProjectSerializer(instance=project, data=request.data)
         if serializer.is_valid():
             serializer.save()
             return Response(serializer.data)
         return Response(serializer.errors)
     return Response(status=status.HTTP_403_FORBIDDEN)
コード例 #5
0
ファイル: project.py プロジェクト: slohr/paperlims
def list_projects_as_json(request):
    logger.debug(request)
    start = int(request.GET.get('start', 0)) + 1
    length = int(request.GET.get('length', 10))

    search_value = None

    if search_value:
        query = Q(name__icontains=search_value) | \
                Q(created_by__last_name__icontains=search_value) | \
                Q(created_by__first_name__icontains=search_value) | \
                Q(created_by__username__icontains=search_value) | \
                Q(status__icontains=search_value)

        logger.debug(Project.objects.filter(query).query)
        objects = Project.objects.filter(query).distinct().order_by(
            'date_created')
    else:
        objects = Project.objects.all().order_by('date_created')

    if objects.count() > length:
        chosen_page = int(math.ceil(float(start) / length))
        page = chosen_page
    else:
        page = 1

    logger.debug("start {0} length {1} page {2}".format(start, length, page))
    paginator = Paginator(objects, length)

    serialzed_objects = ProjectSerializer(Project.objects.all(), many=True)

    data = {
        'recordsTotal': Project.objects.all().count(),
        'recordsFiltered': Project.objects.all().count(),
        'start': start,
        'length': length,
        'data': serialzed_objects.data
    }
    response = JSONRenderer().render(data)
    return HttpResponse(response, content_type='application/json')
コード例 #6
0
 def get(self, request, pk):
     project = self.get_object(pk)
     serializer = ProjectSerializer(project)
     return Response(serializer.data)
コード例 #7
0
 def post(self, request):
     serializer = ProjectSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #8
0
 def get(self, request):
     projects = Project.objects.all()
     serializer = ProjectSerializer(projects, many=True)
     return Response(serializer.data)
コード例 #9
0
 def get(self, request, pk):
     project = get_object_or_404(Project, id=pk)
     if project.creator == request.user:
         serializer = ProjectSerializer(project)
         return Response(serializer.data)
     return Response(status=status.HTTP_403_FORBIDDEN)
コード例 #10
0
 def post(self, request):
     serializer = ProjectSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save(creator=request.user)
         return Response(serializer.data)
     return Response(serializer.errors)
コード例 #11
0
 def get(self, request):
     projects = request.user.projects
     serializer = ProjectSerializer(projects, many=True)
     return Response(serializer.data)
コード例 #12
0
ファイル: project.py プロジェクト: slohr/paperlims
def project_detail_as_json(request, pk):
    project = Project.objects.get(pk=pk)
    response = JSONRenderer().render(ProjectSerializer(project).data)
    return HttpResponse(response, content_type='application/json')