コード例 #1
0
ファイル: views.py プロジェクト: iuriiiv302/task_manager
    def put(self, request):
        validated_data = request.serializer.validated_data
        task = Task.objects.get(pk=validated_data["id"])
        if (task.user_assigned and request.user.id == task.user_assigned.id
            ) or request.user.id == task.user_created.id:
            task.status = validated_data["status"]
            task.save()

            if validated_data["status"] == "finished":
                people = []

                if task.user_assigned and request.user != task.user_assigned:
                    people.append(task.user_assigned.id)
                if request.user != task.user_created:
                    people.append(task.user_created.id)

                comments = Comment.objects.filter(task=task)
                for one_comment in comments:
                    if request.user != one_comment.user:
                        people.append(one_comment.user.id)

                people = list(dict.fromkeys(people))
                users = User.objects.filter(pk__in=people)

                for user in users:
                    AddNotificationTaskStatus(user, task, "finished")
        else:
            return Response(status=403)

        return Response(TaskSerializer(task).data)
コード例 #2
0
    def get(self, request):
        url_parameters = str(request.META['QUERY_STRING'])
        params = url_parameters.split('&')
        task = None

        for param in params:
            if param:
                key = param.split('=')[0]
                if int(param.split('=')[1]) >= 0:
                    valueStart = (int(param.split('=')[1])) * 10
                    valueEnd = int(valueStart) + 10
                    if key == 'page':
                        task = Task.objects.filter(
                            user_created=request.user.id).order_by(
                                "-id")[int(valueStart):int(valueEnd)]

                        # there are no task on this page
                        if not task:
                            return Response(status=204)
                else:
                    return Response(status=400)

        if not task:
            task = Task.objects.filter(
                user_created=request.user.id).order_by("-id")[:10]

        return Response(TaskSerializer(task, many=True).data)
コード例 #3
0
    def post(self, request):
        validated_data = request.serializer.validated_data

        task = Task.objects.create(title=validated_data['title'],
                                   description=validated_data['description'],
                                   status=Task.CREATED,
                                   user_created=request.user,
                                   date_create_task=datetime.now())
        if validated_data['user_assigned']:
            task.user_assigned = validated_data['user_assigned']

        task.save()

        if validated_data['user_assigned'] and validated_data[
                'user_assigned'] != request.user:
            AddNotificationTaskStatus(task.user_assigned, task, "created")

        # add in ReJSON database
        rj = Client(
            host='localhost',
            port=6379,
        )
        rj.jsonset('task:' + str(task.id), Path.rootPath(),
                   TaskSerializer(task).data)
        rj.execute_command('JSON.NUMINCRBY acc .total 1')
        rj.execute_command('JSON.SET acc .maxId ' + str(task.id))

        return Response(status=201)
コード例 #4
0
    def get(self, request):
        now = datetime.datetime.now()
        last_month = now - datetime.timedelta(days=31)
        tasks = Task.objects.filter(
            date_create_task__year=last_month.year,
            date_create_task__month=last_month.month).order_by(
                '-duration')[:20]

        return Response(TaskSerializer(tasks, many=True).data)
コード例 #5
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)
コード例 #6
0
ファイル: views.py プロジェクト: ash018/FFTracker
    def partial_update(self, request, pk, 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:
        ---
            {
                'id': 2
            }
        """
        is_manager(request)
        serializer = TaskSerializer(data=request.data)
        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]
            self.check_object_permissions(request, task)
            with transaction.atomic():
                task = serializer.update_task(serializer.validated_data, task)
                task.delayed = False
                task.save()
            data = {'id': task.id}
            return Response(data, status=200)
        return Response(serializer.errors, status=400)
コード例 #7
0
    def post(self, request):
        validated_data = request.serializer.validated_data

        task = Task.objects.create(
            title=validated_data['title'],
            description=validated_data['description'],
            status=validated_data['status'],
            user_created=request.user,
            user_assigned=request.user,
        )
        task.save()

        return Response(TaskSerializer(task).data)
コード例 #8
0
    def get(self, request):
        rj = Client(
            host='localhost',
            port=6379,
        )

        deleteRedisJSON(rj)

        tasks = Task.objects.all()
        for task in tasks:
            rj.jsonset('task:' + str(task.id), Path.rootPath(),
                       TaskSerializer(task).data)

        accountant = dict()
        accountant.update({"total": tasks.count()})
        accountant.update({"maxId": tasks.last().id})
        rj.jsonset('acc', Path.rootPath(), accountant)

        return Response(status=200)
コード例 #9
0
    def put(self, request):
        validated_data = request.serializer.validated_data
        task = Task.objects.get(pk=validated_data["id"])

        if (task.user_assigned and request.user.id == task.user_assigned.id
            ) or request.user.id == task.user_created.id:
            task.status = validated_data["status"]
            task.save()

            if validated_data["status"] == "finished":
                people = []

                if task.user_assigned and request.user != task.user_assigned:
                    people.append(task.user_assigned.id)
                if request.user != task.user_created:
                    people.append(task.user_created.id)

                comments = Comment.objects.filter(task=task)
                for one_comment in comments:
                    if request.user != one_comment.user:
                        people.append(one_comment.user.id)

                people = list(dict.fromkeys(people))
                users = User.objects.filter(pk__in=people)

                for user in users:
                    AddNotificationTaskStatus(user, task, "finished")

                # stop log for this task
                time_finish = TimeTracker.objects.filter(task=task).last()
                if time_finish:
                    time_finish.finish_time = datetime.now()
                    difference = time_finish.finish_time - time_finish.start_time
                    time_finish.duration = (difference.days * 24 * 60 +
                                            difference.seconds) / 60
                    time_finish.save()
        else:
            return Response(status=403)

        return Response(TaskSerializer(task).data)
コード例 #10
0
    def put(self, request):
        serializer = TaskUpdateAllSerializer(data=request.data)
        if serializer.is_valid():
            data = serializer.validated_data
            if request.user == data["user_created"] or request.user == data[
                    "user_assigned"]:
                task = Task.objects.get(id=data['id'])
                task.user_created = data["user_created"]
                task.user_assigned = data["user_assigned"]
                task.title = data["title"]
                task.description = data["description"]
                task.status = data["status"]
                task.save()

                if task.user_assigned and task.user_assigned != request.user:
                    AddNotificationTaskStatus(task.user_assigned, task,
                                              data["status"])

                response_data = TaskSerializer(task).data
                return Response(response_data)
            else:
                return Response(serializer.errors, status=403)
        else:
            return Response(serializer.errors, status=400)
コード例 #11
0
ファイル: views.py プロジェクト: iuriiiv302/task_manager
 def get(self, request):
     task = Task.objects.filter(user_assigned=request.user.id)
     return Response(TaskSerializer(task, many=True).data)
コード例 #12
0
ファイル: views.py プロジェクト: iuriiiv302/task_manager
 def get(self, request):
     task = Task.objects.filter(status=Task.FINISHED)
     return Response(TaskSerializer(task, many=True).data)