예제 #1
0
파일: views.py 프로젝트: ash018/FFTracker
 def post(self, request, pk, format=None):
     """
     Parameter details:
     ---
         status:
             type: int
             required: Yes
             choices:
                     (4, 'Cancelled'),
                     (5, 'Postponed'),
     """
     is_manager(request)
     if not check_subscription(request):
         return Response({'msg': 'Payment is due!'}, status=402)
     serializer = CTSManagerSerializer(data=request.data,
                                       context={'request': request})
     if serializer.is_valid():
         task_qs = Task.objects.filter(id=pk)
         if len(task_qs) < 1:
             return Response({'detail': 'Task not found!'}, status=400)
         task = task_qs[0]
         with transaction.atomic():
             serializer.cts_manager(task, serializer.validated_data)
         return Response({'msg': 'OK'}, status=200)
     return Response(serializer.errors, status=400)
예제 #2
0
    def create(self, request, format=None):
        """
        Sample Submit:
        ---
            {
                'title': 'texts...',
                'description': 'texts...',
                'manager': 22,
                'assignee': 12,
                'assignee_list': [12, 13],
                'org': 222,

                'deadline': "2019-03-11T07:07:24.000000+00:00",
                'custom_fields': {json field}

            }
        """
        if not check_subscription(request):
            return Response({'msg': 'Payment is due!'}, status=402)
        serializer = AssignmentSerializer(data=request.data)
        if serializer.is_valid():
            instances = 1
            if not check_task_quantity(request, instances):
                return Response({'msg': 'Task limit exceeded!'}, status=402)
            # adjust task count

            assignment = serializer.create_assignment(
                serializer.validated_data, request)
            adjust_task_quantity(request, instances)
            data = get_assignment_data(assignment)
            return Response(data, status=201)
        return Response(serializer.errors, status=400)
예제 #3
0
    def get(self, request, format=None):
        """
        Sample Response:
        ---
            {
                'total_task': 2,
                'current_task': [
                    {
                        'title': 'title',
                        'status': 0,
                        'start': 'datetime',
                        'duration': 4,
                        'task_type': 'string',
                        'address': 'string',
                        'id': 2,
                    },....
                ],
                'delayed_task': 5,
                'remaining_task': 5,
            }

        """
        if not check_subscription(request):
            return Response({'msg': 'Payment is due!'}, status=402)
        agent = request.user
        task_qs = Task.objects.filter(Q(agent_list=agent))
        total_task = task_qs.count()
        remaining_task = task_qs.filter(Q(status=TSTATE['Remaining'])).count()
        delayed_task = task_qs.filter(
            Q(delayed=True) & ~Q(status=TSTATE['Cancelled'])
            & ~Q(status=TSTATE['Postponed'])
            & ~Q(status=TSTATE['Complete'])).count()

        current_task = get_current_task(agent)

        unchecked = get_unchecked_count(request)

        data = {
            'total_task': total_task,
            'current_task': current_task,
            'delayed_task': delayed_task,
            'remaining_task': remaining_task,
            'unchecked_ntf': unchecked,
        }

        return Response(data, status=200)
예제 #4
0
파일: views.py 프로젝트: ash018/FFTracker
    def create(self, request, format=None):
        """
        Sample submit:
        ---
            {
                task_type: 'Doctor visit',
                start: "2019-03-11T07:07:24.000000+00:00",
                deadline: "2019-03-11T07:07:24.000000+00:00",
                "images": ['url1..', 'url2..'],
                point: {'lat': 23.780926, 'lng': 90.422858},
                address: 'Dhaka, Bangladesh',
                image_required: false,
                attachment_required: true,
                org: 111,
                manager: 10,
                agent_list: [1, 2, 3,..]
                custom_fields: {},
                instances: 1,
            }

        Sample response:
        ---
            {
                'ids': [2, 3,..]
            }
        """
        # is_manager(request)
        if not check_subscription(request):
            return Response({'msg': 'Payment is due!'}, status=402)
        serializer = TaskSerializer(data=request.data)
        if serializer.is_valid():

            instances = int(serializer.validated_data['instances'])

            if not check_task_quantity(request, instances):
                return Response({'msg': 'Task limit exceeded!'}, status=402)
            # adjust task count
            adjust_task_quantity(request, instances)

            task_list = serializer.create_task(serializer.validated_data,
                                               request)
            data = {'ids': task_list}
            return Response(data, status=201)
        return Response(serializer.errors, status=400)
예제 #5
0
파일: views.py 프로젝트: ash018/FFTracker
    def post(self, request, pk, format=None):
        """
        Parameter details:
        ---
            pk:
                type: int
                required: Yes
        """
        # is_agent(request)
        if not check_subscription(request):
            return Response({'msg': 'Payment is due!'}, status=402)

        if Task.objects.filter(id=pk):
            task = Task.objects.get(id=pk)
            self.check_object_permissions(request, task)
            agent = request.user
            if agent not in task.agent_list.all():
                task.agent_list.add(agent)
                task.status = TASK_STATUS_DICT['Remaining']
                task.save()
                return Response({'msg': 'OK'}, status=200)
            return Response({'msg': 'Added already!'}, status=200)
        return Response({'msg': 'Task not found!'}, status=400)
예제 #6
0
파일: views.py 프로젝트: ash018/FFTracker
 def partial_update(self, request, pk, format=None):
     """
     Parameter details:
     ---
         status:
             type: int
             required: Yes
             choices:
                     (2, 'In progress'),
                     (3, 'Complete'),
                     (4, 'Cancelled'),
                     (5, 'Postponed'),
         event_point:
             type: json object
             example: {'lat': 23.780926, 'lng': 90.422858}
             required: Yes
         custom_fields:
             type: json object
             general fields: {
                 'image_urls': [{url: 'link1', point: {lat/lng}}, {url: 'link2', point: {lat/lng}}, ..], // If image is required in complete task
                 'attachment_urls': ['link1', 'link2', ..], // If attachment is required in complete task
                 'reason': 'string', // If task is cancelled or postponed
             }
     """
     if not check_subscription(request):
         return Response({'msg': 'Payment is due!'}, status=402)
     serializer = CTSAgentSerializer(data=request.data)
     if serializer.is_valid():
         task_qs = Task.objects.filter(id=pk)
         if len(task_qs) < 1:
             return Response({'msg': 'Task not found!'}, status=400)
         task = task_qs[0]
         self.check_object_permissions(request, task)
         serializer.cts_agent(task, serializer.validated_data, request)
         return Response({'msg': 'OK'}, status=200)
     return Response(serializer.errors, status=400)
예제 #7
0
    def get(self, request, format=None):
        """
        Sample response:
        ---
            {
                'total_task': 12,
                'unassigned_task': 33,
                'delayed_task': 5,
                'remaining_task': 2,
                'complete_task': 3,
                'cancelled_task': 4,
                'inprogress_task': 5,
                'current_task': [
                    {
                        'title': 'title',
                        'status': 0,
                        'start': 'datetime',
                        'duration': 4,
                        'task_type': 'string',
                        'address': 'string',
                        'id': 2,
                    },....
                ],

                'total_agent': 100,
                'offline_agent': 3,
                'online_agent': 4,
                'working_agent': 3,
                'free_agent': 4,
                'unreachable_agent': 5,
                'is_trial': true,
                'due_days': 19,

            }
        """
        is_manager(request)
        adjust_subscription(request)
        if not check_subscription(request):
            return Response({'msg': 'Payment is due!'}, status=402)
        manager = request.user
        task_qf_manager = Q(manager=manager) | Q(agent_list=manager)
        task_qs = Task.objects.filter(task_qf_manager)
        total_task = task_qs.count()
        unassigned_task = task_qs.filter(
            Q(status=TSTATE['Unassigned'])).count()
        remaining_task = task_qs.filter(Q(status=TSTATE['Remaining'])).count()
        delayed_task = task_qs.filter(
            Q(delayed=True) & ~Q(status=TSTATE['Cancelled'])
            & ~Q(status=TSTATE['Postponed'])
            & ~Q(status=TSTATE['Complete'])).count()
        complete_task = task_qs.filter(Q(status=TSTATE['Complete'])).count()
        cancelled_task = task_qs.filter(Q(status=TSTATE['Cancelled'])).count()
        inprogress_task = task_qs.filter(
            Q(status=TSTATE['In progress'])).count()

        current_task = get_current_task(manager)

        resource_qs = User.objects.filter(Q(parent=manager))
        total_agent = resource_qs.count()
        online_agent = resource_qs.filter(Q(is_present=True)).count()
        offline_agent = resource_qs.filter(Q(is_present=False)).count()

        working_agent = resource_qs.filter(
            Q(is_present=True) & Q(is_working=True)
            & Q(is_awol=False)).count()
        free_agent = resource_qs.filter(
            Q(is_present=True) & Q(is_working=False)
            & Q(is_awol=False)).count()
        unreachable_agent = resource_qs.filter(
            Q(is_present=True) & Q(is_awol=True)).count()

        unchecked = get_unchecked_count(request)

        data = {
            'total_task':
            total_task,
            'unassigned_task':
            unassigned_task,
            'delayed_task':
            delayed_task,
            'remaining_task':
            remaining_task,
            'complete_task':
            complete_task,
            'cancelled_task':
            cancelled_task,
            'inprogress_task':
            inprogress_task,
            'current_task':
            current_task,
            'total_agent':
            total_agent,
            'offline_agent':
            offline_agent,
            'online_agent':
            online_agent,
            'working_agent':
            working_agent,
            'free_agent':
            free_agent,
            'unreachable_agent':
            unreachable_agent,
            'is_trial':
            manager.org.subscription._is_trial,
            'due_days': (manager.org.subscription.current_usage.exp_date -
                         timezone.now()).days,
            'unchecked_ntf':
            unchecked,
        }

        return Response(data, status=200)