def post(self, request, *args, **kwargs): if request.method == "POST": lead_form = LeadListForm(request.POST, request.FILES) if lead_form.is_valid(): create_lead_from_file.delay( lead_form.validated_rows, lead_form.invalid_rows, request.user.id, request.get_host(), ) return Response( { "error": False, "message": "Leads created Successfully" }, status=status.HTTP_200_OK, ) else: return Response( { "error": True, "errors": lead_form.errors }, status=status.HTTP_400_BAD_REQUEST, )
def upload_lead_csv_file(request): if request.method == 'POST': lead_form = LeadListForm(request.POST, request.FILES) if lead_form.is_valid(): create_lead_from_file.delay( lead_form.validated_rows, lead_form.invalid_rows, request.user.id) return JsonResponse({'error': False, 'data': lead_form.data}, status=status.HTTP_201_CREATED) else: return JsonResponse({'error': True, 'errors': lead_form.errors}, status=status.HTTP_200_OK)
def upload_lead_csv_file(request): if request.method == "POST": lead_form = LeadListForm(request.POST, request.FILES) if lead_form.is_valid(): create_lead_from_file.delay( lead_form.validated_rows, lead_form.invalid_rows, request.user.id, request.get_host(), request.company.id, ) return JsonResponse( {"error": False, "data": lead_form.data}, status=status.HTTP_201_CREATED ) else: return JsonResponse( {"error": True, "errors": lead_form.errors}, status=status.HTTP_200_OK )
def upload_lead_csv_file(request): if request.method == 'POST': lead_form = LeadListForm(request.POST, request.FILES) if lead_form.is_valid(): print('-- valid lead form submitted, trying to call task --') task = create_lead_from_file.delay(lead_form.validated_rows) return JsonResponse({ 'error': False, 'task_id': task.id }, status=status.HTTP_201_CREATED) else: print('-- POST error on form data --') print('-- lead_form errors: %s' % lead_form.errors) return JsonResponse({ 'error': True, 'errors': lead_form.errors }, status=status.HTTP_200_OK) if request.method == 'GET': task_id = request.GET.get('task_id', None) if task_id: task = AsyncResult(task_id) data = { 'status': 'running', 'state': task.state, 'result': task.result, } return HttpResponse(json.dumps(data), content_type='application/json') data = {'status': 'ready'} return HttpResponse(json.dumps(data), content_type='application/json')