Ejemplo n.º 1
0
def terminate_inprogress_project(request):
    """
	Terminate Asynchronous Image Matching Service
	"""

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

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

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

            if project_count > 0:
                projects = projects.filter(status='InProgress')
                project_count = helper.get_total_project_count(projects)

                if project_count > 0:
                    project = projects[0]
                    project_status = ProjectStatus.objects.get(project=project)
                    async_task_id = project_status.asynctask_id
                    helper.terminate_async_task(task_id=async_task_id)
                    project.status = 'Terminated'
                    project.failed_log = 'Project terminated externally.'
                    project.save()

                    return Response({'response': 'Project Process Terminated'})
                else:
                    return Response({
                        'response':
                        'Project with specified id is not in progress at the moment.'
                    })

            else:
                return Response(
                    {'response': 'Project with specified id not found.'})

        else:
            comp_logger.info('{} is not valid'.format(data))
            comp_logger.info(serializer.errors)
            return Response({'response': serializer.errors})
    return Response({})
Ejemplo n.º 2
0
	def post(self, request, *args, **kwargs):
		comp_logger.info('Call to SearchProjectsByClient')
		serializer = FindProjectByClientSerializer(data=request.data)
		if serializer.is_valid():
			client_name = serializer.data['client_name']
			project_client_lookup = Q(client_name__icontains=client_name)
			comp_logger.info('Call to SearchProjectsByClient with query: {}'.format(client_name))
			projects = Project.objects.filter(project_client_lookup).order_by('-id')
			project_count = helper.get_total_project_count(projects)

			
			if project_count>0:
				paginator = ProjectPageNumberPagination()
				# paginator.page_size = 3
				result_page = paginator.paginate_queryset(projects, request)
				serializer = ProjectDetailSerializer(result_page, many=True)
				return paginator.get_paginated_response(serializer.data)
				# return serializer.data
				# return Response({'response':serializer.data,'total_hits':project_count})
			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})
Ejemplo n.º 3
0
def find_project_detail_report(request):
	"""
	Return 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
				
				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({})
Ejemplo n.º 4
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))

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

			# get project list by date range
			projects = Project.objects.filter(start_date__gte=from_date).filter(start_date__lte=to_date).order_by('-id')
			project_count = helper.get_total_project_count(projects)

			
			if project_count>0:
				paginator = ProjectPageNumberPagination()
				# paginator.page_size = 3						# overrding pagination of result
				result_page = paginator.paginate_queryset(projects, request)
				serializer = ProjectDetailSerializer(result_page, many=True)
				return paginator.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})
Ejemplo n.º 5
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
            })
Ejemplo n.º 6
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})
Ejemplo n.º 7
0
    def get(self, request, project_id, format=None):
        comp_logger.info('Call to ProjectMatchNotMatchCount')
        project = Project.objects.filter(id=project_id)

        project_count = helper.get_total_project_count(project)

        if project_count > 0:
            project = project[0]
            if project.status in ['Completed', 'H_InProgress', 'H_Completed']:
                try:
                    total_matched_count, total_notmatched_count = helper.get_project_match_notmatch_count(
                        project_id)
                except:
                    return Response({
                        'Final computated file not present for project id:{}'.
                        format(project_id)
                    })
                return Response({
                    'Match': total_matched_count,
                    'NotMatch': total_notmatched_count
                })
            else:
                comp_logger.info(
                    'Cannot get result count of a project which is not completed for id:{}'
                    .format(project_id))
                return Response({
                    'response':
                    'Cannot get result count of a project which is not completed'
                })
        else:
            return Response(
                {'response': 'Project with specified id is not completed.'})
Ejemplo n.º 8
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))
			status = serializer.data['status']
			if status!='All':
				status_query = Q(status=status)
				projects = Project.objects.filter(status_query)
			else:
				projects = Project.objects.all()
				

			request_field_list = serializer.data.keys()
			print(request_field_list)
			if 'client_name' in request_field_list:
				client_name = serializer.data['client_name']
				if client_name != '':
					project_client_lookup = Q(client_name__icontains=client_name)
					projects = projects.filter(project_client_lookup).distinct()

			if 'from_date' in request_field_list:
				from_date = serializer.data['from_date']
				if 'to_date' in request_field_list:
					to_date = serializer.data['to_date']
				else:
					to_date = helper.get_current_date()
				from_date, to_date = helper.get_from_date_to_date_format(from_date, to_date)
				if from_date != '' and to_date!='':
					projects = projects.filter(start_date__gte=from_date).filter(start_date__lte=to_date)

			project_count = helper.get_total_project_count(projects)
			if project_count>0:
				projects = projects.order_by('-id')
				paginator = ProjectPageNumberPagination()
				# paginator.page_size = 3						# overrding pagination of result
				result_page = paginator.paginate_queryset(projects, request)
				serializer = ProjectDetailSerializer(result_page, many=True)
				return paginator.get_paginated_response(serializer.data)
			else:
				return Response({'results':[],'count':0})

		else:
			choices_list = [i[0] for i in 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})
Ejemplo n.º 9
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({})
Ejemplo n.º 10
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})
Ejemplo n.º 11
0
	def post(self, request, *args, **kwargs):
		comp_logger.info('Call to SearchProjectsByStatus')
		serializer = FindProjectByStatusSerializer(data=request.data)

		if serializer.is_valid():
			status = serializer.data['status']
			comp_logger.info('Call to find_projects_by_status with status: {}'.format(status))
			project_client_lookup = Q(status=status)
			projects = Project.objects.filter(project_client_lookup).order_by('-id')
			project_count = helper.get_total_project_count(projects)
			if project_count>0:
				paginator = ProjectPageNumberPagination()
				# paginator.page_size = 3						# overrding pagination of result
				result_page = paginator.paginate_queryset(projects, request)
				serializer = ProjectDetailSerializer(result_page, many=True)
				return paginator.get_paginated_response(serializer.data)
			else:
				return Response({'results':[],'count':0})

		else:
			choices_list = [i[0] for i in 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})
Ejemplo n.º 12
0
def start_project(request):
    """
	Start Project Process
	"""

    if request.method == 'PUT':

        data = JSONParser().parse(request)
        serializer = ProjectStartSerializer(data=data)
        comp_logger.info('Call to start_project')
        if serializer.is_valid():
            project_id = serializer.data['id']
            # check if there is another process already running
            currently_running_projects = get_projects_inprogress()
            currently_running_project_count = helper.get_total_project_count(
                currently_running_projects)
            if currently_running_project_count != 0:
                return Response({
                    'response':
                    'Cannot start project for id:{} since another project is already running.'
                    .format(project_id),
                    'started':
                    False
                })
            else:
                try:
                    project = Project.objects.get(id=project_id)
                except Project.DoesNotExist:
                    return Response({
                        'response':
                        'Project with id:{} not found'.format(project_id),
                        'started':
                        False
                    })

                if project.status in [
                        'Completed', 'H_InProgress', 'H_Completed'
                ]:
                    return Response({
                        'response':
                        'Project with id:{} cannot be started as it is already completed.'
                        .format(project_id),
                        'started':
                        False
                    })

                # starting project
                comp_logger.info(
                    'Starting project with id:{}'.format(project_id))

                # check if the input file has been successfully copied
                if helper.check_input_file_exists(project_id,
                                                  project.file_name):
                    project.status = 'InProgress'
                    project.save()
                    project_status = ProjectStatus.objects.filter(
                        project=project)
                    # check if project status is present
                    if len(project_status) > 0:
                        project_status = project_status[0]
                    else:
                        project_status = ProjectStatus(project=project,
                                                       project_phase='1')
                        project_status.save(force_insert=True)

                    comp_logger.info(
                        'calling async task handler for id:{}'.format(
                            project_id))
                    start_async_image_match.delay(
                        project_id=project_id)  # Async Process Start

                    return Response({
                        'response':
                        'Project started for id:{}'.format(project_id),
                        'started':
                        True
                    })
                else:
                    return Response({
                        'response':
                        'Project for id:{} not started as file hasn\'t been copied from ftp location'
                        .format(project_id),
                        'started':
                        False
                    })
        else:
            comp_logger.info('{} is not valid'.format(data))
            comp_logger.info(serializer.errors)
            return Response({'response': serializer.errors})
    return Response({})