def post(self, *args, **kwargs): base_url = self.request.get_host() user = self.request.user data = json.loads(self.request.body) fs_ids = data.get('fs_ids') start_date = data.get('startdate') end_date = data.get('enddate') filterRegion = data.get('filterRegion', None) filterSiteTypes = data.get('siteTypes', None) project = get_object_or_404(Project, pk=self.kwargs.get('pk')) task_obj = CeleryTaskProgress.objects.create(user=user, content_object=project, task_type=3) if task_obj: task = exportProjectSiteResponses.delay(task_obj.pk, user, self.kwargs.get('pk'), base_url, fs_ids, start_date, end_date, filterRegion, filterSiteTypes) task_obj.task_id = task.id task_obj.save() status, data = 200, { 'status': 'true', 'message': 'Sucess, the report is being generated. You will be notified after the report is generated.' } else: status, data = 401, { 'status': 'false', 'message': 'Error occured please try again.' } return JsonResponse(data, status=status)
def post(self, request, pk, *args, **kwargs): report_type = self.request.query_params.get('report_type') project = get_object_or_404(Project, pk=pk) if report_type == 'site_information': source_user = self.request.user data = request.data site_type_ids = data.get('siteTypes', None) region_ids = data.get('regions', None) sync_to_drive = data.get('sync_to_drive', False) task_obj = CeleryTaskProgress.objects.create(user=source_user, content_object=project, task_type=8) if task_obj: task = generateSiteDetailsXls.delay(task_obj.pk, self.kwargs.get('pk'), region_ids, site_type_ids, sync_to_drive) task_obj.task_id = task.id task_obj.save() status, data = 200, {'detail': 'The sites details xls file is being generated. ' 'You will be notified after the file is generated.', 'task_id': task_obj.id} else: status, data = 401, {'detail': 'Error occured please try again.'} return Response(status=status, data=data) elif report_type == 'progress_report': user = self.request.user data = request.data site_type_ids = data.get('siteTypes', None) region_ids = data.get('regions', None) sync_to_drive = data.get('sync_to_drive', False) task_obj = CeleryTaskProgress.objects.create(user=user, task_type=10, content_object=project) if task_obj: task = generate_stage_status_report.delay(task_obj.pk, project.id, site_type_ids, region_ids, sync_to_drive) task_obj.task_id = task.id task_obj.save() status, data = 200, {'detail': 'Progress report is being generated. You will be notified upon ' 'completion. (It may take more time depending upon number of sites ' 'and submissions.)', 'task_id': task_obj.id } else: status, data = 401, {'detail': 'Report cannot be generated a the moment.'} return Response(status=status, data=data) elif report_type == 'form': base_url = self.request.get_host() user = self.request.user data = request.data fs_ids = data.get('fs_ids') start_date = data.get('start_date') end_date = data.get('end_date') region_ids = data.get('regions', None) site_type_ids = data.get('siteTypes', None) project = get_object_or_404(Project, pk=self.kwargs.get('pk')) task_obj = CeleryTaskProgress.objects.create(user=user, content_object=project, task_type=3) if task_obj: task = exportProjectSiteResponses.delay(task_obj.pk, self.kwargs.get('pk'), base_url, fs_ids, start_date, end_date, region_ids, site_type_ids) task_obj.task_id = task.id task_obj.save() status, data = 200, {'detail': 'Success, the report is being generated. You will be notified after ' 'the report is generated.', 'task_id': task_obj.id } else: status, data = 401, {'detail': 'Error occured please try again.'} return Response(status=status, data=data) elif report_type == 'project_logs': user = self.request.user data = request.data reportType = data.get('type') start_date = data.get('start_date') end_date = data.get('end_date') if reportType == "Project": obj = get_object_or_404(Project, pk=self.kwargs.get('pk')) else: obj = get_object_or_404(Site, pk=self.kwargs.get('pk')) task_obj = CeleryTaskProgress.objects.create(user=user, content_object=obj, task_type=12) if task_obj: task = exportLogs.delay(task_obj.pk, self.kwargs.get('pk'), reportType, start_date, end_date) task_obj.task_id = task.id task_obj.save() status, data = 200, {'status': 'true', 'message': 'Success, the report is being generated. You will be notified after ' 'the report is generated.', 'task_id': task_obj.id } else: status, data = 401, {'status': 'false', 'message': 'Error occured please try again.'} return Response(data, status=status) elif report_type == 'user_activity_report': user = request.user data = request.data start_date = data.get('start_date') end_date = data.get('end_date') print('datattatata', data) task_obj = CeleryTaskProgress.objects.create(user=user, task_type=16, content_object=project) if task_obj: task = exportProjectUserstatistics.delay(task_obj.pk, project.id, start_date, end_date) task_obj.task_id = task.id task_obj.save() data = {'status': 'true', 'message': 'User Activity report is being generated. You will be notified upon completion.', 'task_id': task_obj.id } else: data = {'status': 'false', 'message': 'Report cannot be generated a the moment.'} return Response(data, status=200) elif report_type == 'activity_report': user = self.request.user data = request.data reportType = data.get('type') start_date = data.get('start_date') end_date = data.get('end_date') task_obj = CeleryTaskProgress.objects.create(user=user, content_object=project, task_type=11) if task_obj: task = exportProjectstatistics.delay(task_obj.pk, self.kwargs.get('pk'), reportType, start_date, end_date) task_obj.task_id = task.id task_obj.save() status, data = 200, {'status': 'true', 'message': 'Success, the report is being generated. You will be notified after ' 'the report is generated.', 'task_id': task_obj.id } else: status, data = 401, {'status': 'false', 'message': 'Error occured please try again.'} return Response(data, status=status)