Exemplo n.º 1
0
def rate(request,pk):
    "rate a doctor with id pk"
    avg=0
    serializer = RateSerializer(data=request.data)
    if serializer.is_valid():
        serializer.save()
        doctor=Rate.objects.filter(rate_to=pk)
        for x in range(0,len(doctor)):
            avg+=doctor[x].rate
        avg=avg/len(doctor)
        
        try:
            doc=AverageRate.objects.get(doc_id=pk)
        except AverageRate.DoesNotExist:
            dict1 = {'doc_id':int(pk), 'rate': avg, }
            qdict = QueryDict('',mutable=True)
            qdict.update(dict1)
            serializer2=AverageRateSerializer(data=qdict)
            if serializer2.is_valid():
                serializer2.save()
                return Response(serializer2.data, status=status.HTTP_201_CREATED)
        doctorupdate=AverageRate.objects.filter(doc_id=pk).update(rate=avg)
        doc=AverageRate.objects.get(doc_id=pk)
        serializer3=AverageRateSerializer(doc)
        return Response(serializer3.data, status=status.HTTP_201_CREATED)
    else:
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
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)
Exemplo n.º 3
0
def rate(request, pk):
    "rate a doctor with id pk"
    avg = 0
    serializer = RateSerializer(data=request.data)
    if serializer.is_valid():
        serializer.save()
        doctor = Rate.objects.filter(rate_to=pk)
        for x in range(0, len(doctor)):
            avg += doctor[x].rate
        avg = avg / len(doctor)

        try:
            doc = AverageRate.objects.get(doc_id=pk)
        except AverageRate.DoesNotExist:
            dict1 = {
                'doc_id': int(pk),
                'rate': avg,
            }
            qdict = QueryDict('', mutable=True)
            qdict.update(dict1)
            serializer2 = AverageRateSerializer(data=qdict)
            if serializer2.is_valid():
                serializer2.save()
                return Response(serializer2.data,
                                status=status.HTTP_201_CREATED)
        doctorupdate = AverageRate.objects.filter(doc_id=pk).update(rate=avg)
        doc = AverageRate.objects.get(doc_id=pk)
        serializer3 = AverageRateSerializer(doc)
        return Response(serializer3.data, status=status.HTTP_201_CREATED)
    else:
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 4
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)