Beispiel #1
0
 def put(self, request, pk, format=None):
     snippet = self.get_object(pk)
     serializer = TaskSerializer(snippet, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #2
0
 def get(self, request, *args, **kwargs):
     user = request.user
     descendants = user.profile.directing_department.members.all().exclude(
         id=user.profile.id) if hasattr(
             user.profile,
             "directing_department") else user.profile.child_members.all()
     data = {
         "descendants":
         ProfileSerializer(descendants, many=True).data,
         "profile":
         ProfileSerializer(user.profile).data,
         "ancestor":
         ProfileSerializer(user.profile.manager).data,
         "tasks":
         TaskSerializer(user.profile.tasks, many=True).data,
         "pips":
         PipSerializer(user.pips.all(), many=True).data if hasattr(
             user, "pips") else [],
         "raised_pips":
         PipSerializer(user.raised_pips.all(), many=True).data if hasattr(
             user, "raised_pips") else [],
         "pending_tasks":
         TaskSerializer(user.profile.pending_tasks, many=True).data,
         "kras":
         KraSerializer(user.kras.all(), many=True).data if hasattr(
             user, "kras") else []
     }
     return Response(utils.build_response(True, None, data))
Beispiel #3
0
 def put(self, request, pk, format=None):
     task = self.get_object(pk)
     request.data["edited"] = datetime.now()
     serializer = TaskSerializer(task, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200_OK)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #4
0
 def put(self, request, pk):
     # ipdb.set_trace()
     task = get_object_or_404(Task, pk=pk)
     serializer = TaskSerializer(task, data=request.data)
     if not serializer.is_valid():
         ipdb.set_trace()
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
     serializer.save()
     return Response({'task': get_object_or_404(Task, pk=pk)})
Beispiel #5
0
    def post(self, request, format=None):

        owner = request.user
        serializer_context = {'request': request, }
        serializer = TaskSerializer(data=request.data, context=serializer_context)
        if serializer.is_valid():
            serializer.save(owner=owner)
            return self.get(request)
        else:
            ipdb.set_trace()
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #6
0
    def post(self, request, pk, format=None):
        task = self.get_object(pk)
        date = datetime.now()
        if (task.status):
            date = None
        data = {"status": not task.status, "concluded": date}

        serializer = TaskSerializer(task, data=data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_200_OK)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #7
0
 def post(self, request):
     validate_error = task_validation(request.data)
     if validate_error is not None:
         return Response(prepare_error_response(validate_error),
                         status=status.HTTP_400_BAD_REQUEST)
     serializer = TaskSerializer(data=request.data)
     if serializer.is_valid(raise_exception=True):
         serializer.save()
         return Response(prepare_create_success_response(serializer.data),
                         status=status.HTTP_200_OK)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Beispiel #8
0
    def post(self, request, survivor_id):
        request.data['survivor'] = survivor_id
        request.data['advocate'] = request.user.user_token

        serializer = TaskSerializer(data=request.data)

        if serializer.is_valid(raise_exception=True):
            task = serializer.save()
            send_push_message(token=Survivor.objects.get(
                user__user_token=survivor_id).user.device_token,
                              message='task',
                              notification_type='task-assigned',
                              data={'details': task.details})
            return Response(TaskSerializer(task).data,
                            status=status.HTTP_201_CREATED)
Beispiel #9
0
 def view(self, user, pk):
     ''' checing whether the task id exists or not'''
     if Task.objects.filter(id=pk).exists():
         ''' task instance '''
         task = Task.objects.get(id=pk)
         ''' checking whether the task belongs to the requested user '''
         if task.created_by == user:
             serializer = TaskSerializer(task)
             ''' success response '''
             return Response(
                 {
                     'success': True,
                     'message': 'Task details successfully fetched',
                     'data': serializer.data,
                 },
                 status=status.HTTP_200_OK)
         ''' unauthorized access response '''
         return Response(
             {
                 'success': False,
                 'error': 'Task does not belong to {}'.format(user.email),
             },
             status=status.HTTP_401_UNAUTHORIZED)
     ''' invalid task id response '''
     return Response({
         'success': False,
         'error': 'Invalid Task id',
     },
                     status=status.HTTP_404_NOT_FOUND)
Beispiel #10
0
 def get(self, request, format=None):
     tasks = Task.objects.filter(owner=request.user)
     serializer = TaskSerializer(tasks, many=True)  # Ojo con el many true
     if len(tasks) == 0:
         return Response(status=status.HTTP_204_NO_CONTENT)
     else:
         return Response(serializer.data, status=status.HTTP_200_OK)
class FolderSerializer(serializers.ModelSerializer):
    task_set = TaskSerializer(many=True, read_only=True)

    class Meta:
        model = Folder
        fields = ('id', 'name', 'owner', 'task_set')
        read_only_fields = ('owner', )
Beispiel #12
0
def create(request):
    if request.method == 'POST':
        data = JSONParser().parse(request)
        data["created"] = datetime.today()
        data["uid"] = uuid.uuid1()
        data["uid"] = uuid.uuid1()
        serializer = TaskSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            message = MessageGenerator(uid=data["uid"],
                                       script=data["script"],
                                       arguments=data["arguments"])
            messenger.submit(message.generate_message())
            return JsonResponse(serializer.data, status=201)
        return JsonResponse(serializer.errors, status=400)

    if request.method == 'GET':
        return HttpResponse(status=405)
Beispiel #13
0
    def post(self, request):
        serialized_object = TaskSerializer(data=request.data)
        if not serialized_object.is_valid():
            res = str(serialized_object.errors)
            Status = status.HTTP_400_BAD_REQUEST
            message = res
            response = {"status": Status, "message": message}
            logger.info("upload_statement response: " + str(response))
            return Response(response, Status)
        message = "Unauthorized"
        Status = status.HTTP_500_INTERNAL_SERVER_ERROR
        response = {"message": message, "status": Status}
        request_params = request.data
        list_name = request_params.get('list_name')
        task_name = request_params.get('task_name')
        description = request_params.get('desc')
        due_date = request_params.get('due_date')
        label = request_params.get('label')
        status_task = request_params.get('status')
        priority = request_params.get('priority')

        try:
            task_obj = Task.objects.create(task_name=task_name,
                                           task_desc=description,
                                           due_date=due_date,
                                           list_name=list_name,
                                           label=label,
                                           status=status_task,
                                           priority=priority)
            if task_obj:
                response = {
                    "message": "success",
                    "description": "Data Uploded successfully"
                }
                Status = status.HTTP_200_OK
        except Exception as e:
            print(e)
            response = {
                "message": "error",
                "description": "Something went wrong"
            }
            Status = status.HTTP_500_INTERNAL_SERVER_ERROR

        return Response(response, Status)
Beispiel #14
0
 def update(self, pk, data, user):
     ''' checking whether the tasks id exists or not '''
     if Task.objects.filter(id=pk).exists():
         ''' getting task object '''
         task = Task.objects.get(id=pk)
         ''' checking whether the task belongs to the requested user '''
         if task.created_by == user:
             serializer = TaskSerializer(data=data, instance=task)
             ''' checking whether the serializer is valid or not '''
             if serializer.is_valid():
                 ''' updating task details '''
                 serializer.update(instance=task,
                                   validated_data=serializer.validated_data)
                 ''' success response '''
                 return Response(
                     {
                         'success': True,
                         'message': f'Task: {pk}, successfully updated',
                         'data': serializer.data,
                     },
                     status=status.HTTP_200_OK)
             return Response(
                 {
                     'success': False,
                     'error': f'Failed to update task: {pk}',
                     'message': serializer.errors,
                 },
                 status=status.HTTP_400_BAD_REQUEST)
         ''' unauthorized access response '''
         return Response(
             {
                 'success':
                 False,
                 'error':
                 'Task: {} does not belong to {}'.format(pk, user.email),
             },
             status=status.HTTP_401_UNAUTHORIZED)
     ''' invalid task id response '''
     return Response(
         {
             'success': False,
             'error': f'No task found with id: {pk}',
         },
         status=status.HTTP_404_NOT_FOUND)
Beispiel #15
0
def view_pk(request, pk):
    try:
        task = Task.objects.get(pk=pk)
        task.arguments = ast.literal_eval(task.arguments)
    except Task.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = TaskSerializer(task)
        return JsonResponse(serializer.data)
Beispiel #16
0
def get_process_tasks(request, id):
    try:
        process = models.Process.objects.get(id=id)
        tasks = Task.objects.filter(process=process)

        serializer = TaskSerializer(tasks, many=True)

        return Response({'tasks': serializer.data})
    except:
        return Response({'error': 'Bir hata oluştu'})
Beispiel #17
0
    def put(self, request, survivor_id):
        task = Task.objects.get(id=request.data.get('task_id'))

        task.status = request.data.get('status', task.status)
        task.type = request.data.get('type', task.type)
        task.deadline = request.data.get('deadline', task.deadline)

        task.save()

        return Response(TaskSerializer(task).data, status=status.HTTP_200_OK)
Beispiel #18
0
    def put(self, request, pk):
        validate_error = task_validation(request.data)
        if validate_error is not None:
            return Response(prepare_error_response(validate_error),
                            status=status.HTTP_400_BAD_REQUEST)

        task = self.get_object(pk)
        if task is not None:
            serializer = TaskSerializer(task, data=request.data)
            if serializer.is_valid():
                serializer.save()
                return Response(prepare_create_success_response(
                    serializer.data),
                                status=status.HTTP_201_CREATED)
            return Response(prepare_error_response(serializer.errors),
                            status=status.HTTP_400_BAD_REQUEST)
        else:
            return Response(
                prepare_error_response("No addons found for this ID"),
                status=status.HTTP_400_BAD_REQUEST)
Beispiel #19
0
 def mutate(root, info, data):
     try:
         instance = Task.objects.get(id=data['id'])
     except Task.DoesNotExist:
         return UpdateTask(errors=[
             CustomErrorType(field='nonFieldErrors',
                             messages=[gettext('Task does not exist.')])
         ])
     serializer = TaskSerializer(instance=instance, data=data, partial=True)
     if errors := mutation_is_not_valid(serializer):
         return UpdateTask(errors=errors, ok=False)
Beispiel #20
0
class RoundSerializer(serializers.ModelSerializer):
    author = serializers.SerializerMethodField()
    tasks = TaskSerializer(many=True)

    def get_author(self, obj: Round):
        return obj.tournament.author_id

    class Meta:
        model = Round
        fields = ('id', 'title', 'tournament', 'author', 'is_final',
                  'is_selection', 'tasks')
Beispiel #21
0
def view_uid(request, uid):
    try:
        task = Task.objects.get(uid=uid)
        task.arguments = ast.literal_eval(task.arguments)
    except Task.DoesNotExist:
        return HttpResponse(status=404)
    except ValidationError as e:
        return HttpResponse(e, status=400)

    if request.method == 'GET':
        serializer = TaskSerializer(task)
        return JsonResponse(serializer.data)
Beispiel #22
0
 def list(self, user):
     ''' Filtering tasks based on request user id '''
     tasks = Task.objects.filter(created_by=user, is_deleted=False)
     ''' task serializer '''
     serializer = TaskSerializer(tasks, many=True)
     ''' success response '''
     return Response(
         {
             'success': True,
             'message': 'Task list successfully fetched',
             'data': serializer.data,
         },
         status=status.HTTP_200_OK)
Beispiel #23
0
    def post(self, request):

        task_serializer = TaskSerializer(data=request.data)

        if not task_serializer.is_valid():
            return Response(task_serializer.errors,
                            status=http_status_code.HTTP_400_BAD_REQUEST)

        validated_data = task_serializer.validated_data
        task = Task.objects.create(task_id=validated_data.get('task_id'),
                                   file_id=validated_data.get('file_id'),
                                   status=validated_data.get('status'),
                                   result=validated_data.get('result'))

        # # Cache
        # cache_key = 'task_id'
        # cache.set(cache_key, "First Task for analysis")

        # Async call for analysing file.
        analyze_file.delay(validated_data.get('task_id'))

        return Response(task_serializer.data,
                        status=http_status_code.HTTP_201_CREATED)
Beispiel #24
0
 def get(self, request, *args, **kwargs):
     messages = Message.objects.filter(
         kra__in=request.user.kras.all(),
         read=False).exclude(user=request.user)
     serializer = KraMessagesSerializer(messages,
                                        many=True,
                                        context={"request": request})
     data = {"messages": serializer.data}
     tasks = request.user.profile.unseen_tasks
     serializer = TaskSerializer(tasks, many=True)
     data["tasks"] = serializer.data
     messages.update(read=True)
     tasks.update(seen=True)
     return Response(utils.build_response(True, None, data))
Beispiel #25
0
    def get(self, request, task_id=None):

        file_id = request.GET.get('uuid')

        if file_id:
            tasks = Task.objects.filter(file_id=file_id)

        elif task_id:
            tasks = Task.objects.filter(task_id=task_id)

        else:
            tasks = Task.objects.all()

        serializer = TaskSerializer(tasks, many=True)
        return Response(serializer.data, status=http_status_code.HTTP_200_OK)
Beispiel #26
0
def task_collection(request):

	#To view all Task Objects
    if request.method == 'GET':
        tasks = Task.objects.all()
        serializer = TaskSerializer(tasks, many=True) #Serialize all value to be sent over
        return Response(serializer.data)
    
    #To create a new Task Object
    elif request.method == 'POST':
    	data = {
    		'title' : request.data.get('title'),
    		'description' : request.data.get('description')
    		} 
    	
    	serializer = TaskSerializer(data=data)
    	

    	#If the task serializer is valid then save it, otherwise return 400 bad request
    	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)
Beispiel #27
0
 def create(self, data, user):
     ''' checking the validity of serializer '''
     serializer = TaskSerializer(data=data, context={'user': user})
     ''' checking whether the API payload is valid or not '''
     if serializer.is_valid():
         ''' creating new task'''
         task = serializer.save()
         if task:
             ''' success response '''
             return Response(
                 {
                     'success': True,
                     'message': 'Task successfully created',
                     'data': serializer.data,
                 },
                 status=status.HTTP_201_CREATED)
     ''' serializer error response '''
     return Response(
         {
             'success': False,
             'error': 'Failed to create new task',
             'message': serializer.errors,
         },
         status=status.HTTP_400_BAD_REQUEST)
Beispiel #28
0
 def test_retrieve_tasks(self):
     """Test retrieving authenticated User Tasks"""
     Task.objects.create(user=self.user,
                         title='First Title',
                         body='First Body')
     Task.objects.create(user=self.user,
                         title='Second Title',
                         body='Second Body')
     # HTTP GET request
     res = self.client.get(TASKS_URL)
     tasks = Task.objects.all().order_by('date_created')
     serializer = TaskSerializer(tasks, many=True)  # returns MANY Tasks
     # Assertions
     self.assertEqual(res.status_code, status.HTTP_200_OK)
     self.assertEqual(res.data, serializer.data)
Beispiel #29
0
 def post(self, request):
     # permission_classes = (IsAuthenticated,)
     serializer_class = TaskSerializer(
         data={
             "id": self.request.data.get('id'),
             "name": self.request.data.get('name'),
             "assignee": self.request.data.get('assignee'),
             "process_id": self.request.data.get('process_id')
         })
     serializer_class.is_valid()
     serializer_class.save()
     url = 'http://dev.cheesenology.kz:8080/engine-rest/task'
     json = {
         "taskVariables": [{
             "name": self.request.data.get('name'),
             "value": "varValue",
             "operator": "eq"
         }, {
             "name": self.request.data.get('name'),
             "value": 30,
             "operator": "neq"
         }],
         "processInstanceBusinessKeyIn":
         "aBusinessKey,anotherBusinessKey",
         "assigneeIn":
         self.request.data.get('assignee'),
         "priority":
         10,
         "sorting": [{
             "sortBy": "dueDate",
             "sortOrder": "asc"
         }, {
             "sortBy": "processVariable",
             "sortOrder": "desc",
             "parameters": {
                 "variable": "orderId",
                 "type": "String"
             }
         }]
     }
     # surname, name = (str(self.request.data.get('fio')) + " ").split(" ", 1)
     # json = {
     #     "profile": {
     #         "id": str(self.request.data.get('id')),
     #         "name": str(self.request.data.get('name')),
     #         "assignee": int(self.request.data.get('assignee')),
     #         "process_id": str(self.request.data.get('process_id'))
     #         # "credentials": {
     #         #     "password": self.request.data.get('password')
     #         # }
     #     }
     # }
     requests.post(url, json=json)
     return Response(serializer_class.data, status=status.HTTP_200_OK)
Beispiel #30
0
def task_list(request):
    '''
    List all tasks, or create a new task.
    '''
    if request.method == 'GET':
        tasks = Task.objects.all()
        serializer = TaskSerializer(tasks, many=True)
        return Response(serializer.data)
    elif request.method == 'POST':
        serializer = TaskSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Beispiel #31
0
    def retrieve(self, request, pk):
        print(request.user)

        if request.user.is_anonymous:
            return http.HttpResponseForbidden()

        try:
            task = Task.objects.get(id=pk)
        except Task.DoesNotExist:
            return http.HttpResponseNotFound()

        data = TaskSerializer(task).data
        data['solutions'] = [
            sol for sol in data['solutions']
            if sol['author'] == request.user.id
        ]

        return http.JsonResponse(data)