コード例 #1
0
ファイル: views.py プロジェクト: andy-cruk/citsci-userdata
def api_citzenopinion_get(request):
    if request.method == 'POST':
        r_data = request.data
        fn = r_data.get('full_name')
        data = {
            'full_name': request.data.get('full_name'),
            'short_name': request.data.get('short_name')
        }
        serializer = CitizenSerializer(data=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)
コード例 #2
0
ファイル: views.py プロジェクト: CRUKorg/citsci-userdata
def citizen_list(request):
    if request.method == 'GET':
        citizens = Citizen.objects.all()
        serializer = CitizenSerializer(citizens, many=True)
        return Response(serializer.data)
    elif request.method == 'POST':
        r_data = request.data
        fn = r_data.get('full_name')
        data = {'full_name': request.data.get('full_name'), 'short_name': request.data.get('short_name')}
        serializer = CitizenSerializer(data=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)
コード例 #3
0
ファイル: views.py プロジェクト: CRUKorg/citsci-userdata
def citizen_detail(request, pk):
    try:
        citizen = Citizen.objects.get(pk=pk)
    except Citizen.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = CitizenSerializer(citizen)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = CitizenSerializer(citizen, data=request.DATA)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        citizen.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
コード例 #4
0
ファイル: views.py プロジェクト: andy-cruk/citsci-userdata
def citizen_list(request):
    if request.method == 'GET':
        citizens = Citizen.objects.all()
        serializer = CitizenSerializer(citizens, many=True)
        return Response(serializer.data)
    elif request.method == 'POST':
        r_data = request.data
        fn = r_data.get('full_name')
        data = {
            'full_name': request.data.get('full_name'),
            'short_name': request.data.get('short_name')
        }
        serializer = CitizenSerializer(data=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)
コード例 #5
0
ファイル: views.py プロジェクト: andy-cruk/citsci-userdata
def citizen_detail(request, pk):
    try:
        citizen = Citizen.objects.get(pk=pk)
    except Citizen.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = CitizenSerializer(citizen)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = CitizenSerializer(citizen, data=request.DATA)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        citizen.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
コード例 #6
0
ファイル: views.py プロジェクト: andy-cruk/citsci-userdata
def citizen_test(request):
    if request.method == 'GET':
        citizens = Citizen.objects.all()
        serializer = CitizenSerializer(citizens, many=True)
        return Response(serializer.data)