Exemple #1
0
    def post(self, request, *args, **kwargs):
        comp_logger.info('Call to SearchProjectsByClientDateStatus')
        serializer = FindProjectByClientDateStatusSerializer(data=request.data)

        if serializer.is_valid():
            comp_logger.info(
                'Call to SearchProjectsByClientDateStatus with request: {}'.
                format(request.data))
            projects = self.get_queryset(serializer)
            project_count = helper.get_total_project_count(projects)
            if project_count > 0:
                result_set = self.paginate_queryset(projects)
                if result_set is not None:
                    serializer = ProjectDetailSerializer(result_set, many=True)
                    return self.get_paginated_response(serializer.data)
            else:
                return Response({'results': [], 'count': 0})

        else:
            choices_list = [i[0] for i in settings.PROJECT_STATUS_LIST]
            comp_logger.info('{} is not valid'.format(request.data))
            comp_logger.info(serializer.errors)
            return Response({
                'response': serializer.errors,
                'status_options': choices_list
            })
Exemple #2
0
    def post(self, request, *args, **kwargs):
        comp_logger.info('Call to SearchProjectsByDate')
        serializer = FindProjectByDateSerializer(data=request.data)

        if serializer.is_valid():
            from_date = serializer.data['from_date']
            to_date = serializer.data['to_date']
            comp_logger.info(
                'Call to SearchProjectsByDate with range: {} and {}'.format(
                    from_date, to_date))

            self.from_date, self.to_date = helper.get_from_date_to_date_format(
                from_date, to_date)

            # get project list by date range
            projects = self.get_queryset()
            project_count = helper.get_total_project_count(projects)

            if project_count > 0:
                result_set = self.paginate_queryset(projects)
                if result_set is not None:
                    serializer = ProjectDetailSerializer(result_set, many=True)
                    return self.get_paginated_response(serializer.data)
            else:
                return Response({'results': [], 'count': 0})

        else:
            comp_logger.info('{} is not valid'.format(request.data))
            comp_logger.info(serializer.errors)
            return Response({'response': serializer.errors})
Exemple #3
0
def find_project_detail_report(request):
    """
	Returns Detailed Project Report
	"""

    if request.method == 'POST':
        comp_logger.info('Call to find_project_detail_report')
        data = JSONParser().parse(request)
        serializer = ProjectStartSerializer(data=data)

        if serializer.is_valid():
            project_id = serializer.data['id']
            comp_logger.info(
                'Call to find_project_detail_report with id: {}'.format(
                    project_id))

            projects = Project.objects.filter(
                id=project_id).prefetch_related('projectstatus_set')
            project_count = helper.get_total_project_count(projects)

            if project_count > 0:
                project = projects[0]
                serializer = ProjectDetailSerializer(projects, many=True)
                detailed_response_dict = dict(serializer.data[0])

                if project.status != 'Pending':
                    detailed_response_dict[
                        'project_phase'] = settings.PROJECT_PROCESS_STATUS_DICT[
                            project.projectstatus_set.all()[0].project_phase]
                    detailed_response_dict[
                        'project_completion_percentage'] = project.projectstatus_set.all(
                        )[0].project_completion_percentage
                    detailed_response_dict[
                        'project_completion_datetime'] = project.projectstatus_set.all(
                        )[0].last_updated_date
                    detailed_response_dict[
                        'project_process_initiation_datetime'] = project.projectstatus_set.all(
                        )[0].start_datetime

                return Response({
                    'response': detailed_response_dict,
                    'total_hits': project_count
                })
            else:
                return Response({'response': [], 'total_hits': 0})

        else:
            comp_logger.info('{} is not valid'.format(data))
            comp_logger.info(serializer.errors)
            return Response({'response': serializer.errors})
    return Response({})
Exemple #4
0
    def post(self, request, *args, **kwargs):
        comp_logger.info('Call to SearchProjectsByClient')
        serializer = FindProjectByClientSerializer(data=request.data)
        if serializer.is_valid():
            self.client_name = serializer.data['client_name']
            comp_logger.info(
                'Call to SearchProjectsByClient with query: {}'.format(
                    self.client_name))
            request_field_list = serializer.data.keys()
            projects = self.get_queryset(
            )  # get object instances matching the post request
            project_count = helper.get_total_project_count(projects)

            if project_count > 0:

                # no need for pagination
                if 'all' in request_field_list:
                    serializer = ProjectDetailSerializer(projects, many=True)
                    return Response({
                        'results': serializer.data,
                        'count': project_count
                    })

                # handling of LimitOffsetPagination
                else:
                    result_set = self.paginate_queryset(projects)
                    if result_set is not None:
                        serializer = ProjectDetailSerializer(result_set,
                                                             many=True)
                        return self.get_paginated_response(serializer.data)
            else:
                return Response({'results': [], 'count': 0})

        else:
            comp_logger.info('{} is not valid'.format(request.data))
            comp_logger.info(serializer.errors)
            return Response({'response': serializer.errors})
Exemple #5
0
def get_inprogress_project(request):
    """
	Returns list of Projects currently in progress
	"""
    if request.method == 'GET':
        comp_logger.info('Call to get_inprogress_project')
        currently_running_projects = get_projects_inprogress()
        project_count = helper.get_total_project_count(
            currently_running_projects)
        if project_count > 0:
            serializer = ProjectDetailSerializer(currently_running_projects,
                                                 many=True)
            return Response({'response': serializer.data})
        else:
            return Response({'response': []})
    return Response({})
Exemple #6
0
def create_project(request):
    """
	Create project and return information
	"""
    if request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = ProjectInitSerializer(data=data)
        comp_logger.info('Call to create_project')
        if serializer.is_valid():
            client_name = serializer.data['client_name']
            file_name = serializer.data['file_name']

            # project = Project(status='Pending', client_name=client_name,file_name=file_name, total_records=total_records,total_unique_products=total_unique_products)

            # Project save section
            try:
                project = Project(status='Pending',
                                  client_name=client_name,
                                  file_name=file_name)
                project.save(force_insert=True)
                comp_logger.info('Project created with id: {}'.format(
                    project.id))

            except Exception as e:
                # Raise an issue if the project cannot be saved. Most likely due to ftp file transfer failure
                comp_logger.info(
                    'Cannot save project for client_name:{} and file:{}'.
                    format(client_name, file_name))
                return Response({'response': str(e)})

            serializer = ProjectDetailSerializer(project)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            comp_logger.info('{} is not valid'.format(data))
            comp_logger.info(serializer.errors)
            return Response({'response': serializer.errors})
    return Response({})
Exemple #7
0
 def get(self, request, pk, format=None):
     project = self.get_object(pk)
     serializer = ProjectDetailSerializer(project)
     return Response(serializer.data)