Пример #1
0
def doctor_list(request):
    """
    List all tasks, or create a new task.
    """
    if request.method == 'GET':
        doctors = Doctor.objects.all()
        serializer = DoctorSerializer(doctors, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = DoctorSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            getid=Doctor.objects.filter(email=request.data["email"])
            print getid[0].id
            dict1 = {'doc_id':getid[0].id, 'rate':'0', }   
            qdict = QueryDict('',mutable=True)
            qdict.update(dict1)
            serializer2=AverageRateSerializer(data=qdict)
            if serializer2.is_valid():
                serializer2.save()

            dict2 = {'doc_id':getid[0].id, 'rate': '0',}
            qdict = QueryDict('',mutable=True)
            qdict.update(dict2)
            serializer2=AverageComRateSerializer(data=dict2)
            if serializer2.is_valid():
                serializer2.save()
                
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(
                serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
def doctor_detail(request, pk):
    """
    Get, udpate, or delete a specific task
    """
    try:
        doctor = Doctor.objects.get(pk=pk)
    except Doctor.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = DoctorSerializer(doctor)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = DoctorSerializer(doctor, 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':
        doctor.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
Пример #3
0
def doctor_detail(request, pk):
    """
    Get, udpate, or delete a specific task
    """
    try:
        doctor = Doctor.objects.get(pk=pk)
    except Doctor.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = DoctorSerializer(doctor)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = DoctorSerializer(doctor, 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':
        doctor.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
Пример #4
0
def averagerate(request, pk):
    "get average of comment and rate"
    c = AverageComRate.objects.filter(doc_id=pk)
    r = AverageRate.objects.filter(doc_id=pk)
    avg = c[0].rate + r[0].rate
    avg /= 2
    doc = Doctor.objects.filter(id=pk).update(rate=avg)
    doc = Doctor.objects.get(id=pk)
    serializer = DoctorSerializer(doc)
    return Response(serializer.data, status=status.HTTP_201_CREATED)
Пример #5
0
def doctor_email(request, email):
    "method is for users who reinstalled the app"
    try:
        doctor = Doctor.objects.get(email=email)
    except Doctor.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = DoctorSerializer(doctor)
        return Response(serializer.data)
Пример #6
0
def get_doclist(request, catID):
    "method to get list of doctors for a given category ID"
    try:
        doc = Doclist.objects.filter(catID=catID)
    except Doclist.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)
    out_id = []
    for x in range(0, len(doc)):
        out_id.append(doc[x].usrID)
    doctor = Doctor.objects.filter(pk__in=out_id)
    serializer = DoctorSerializer(doctor, many=True)
    return Response(serializer.data)
Пример #7
0
def doctor_list(request):
    """
    List all tasks, or create a new task.
    """
    if request.method == 'GET':
        doctors = Doctor.objects.all()
        serializer = DoctorSerializer(doctors, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = DoctorSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            getid = Doctor.objects.filter(email=request.data["email"])
            dict1 = {
                'doc_id': getid[0].id,
                'rate': '0',
            }
            qdict = QueryDict('', mutable=True)
            qdict.update(dict1)
            serializer2 = AverageRateSerializer(data=qdict)
            if serializer2.is_valid():
                serializer2.save()

            dict2 = {
                'doc_id': getid[0].id,
                'rate': '0',
            }
            qdict = QueryDict('', mutable=True)
            qdict.update(dict2)
            serializer2 = AverageComRateSerializer(data=dict2)
            if serializer2.is_valid():
                serializer2.save()

            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)