def post(self, request, *args, **kwargs): message = 'Success' status = 'success' if 'new_task_queue' not in request.POST: tq_form = TaskQueueChoiceForm(request.POST) if not tq_form.is_valid(): status = 'error' message = 'Please choose Task Queue' else: tq_form = TaskQueueForm(request.POST) project_form_class = ProjectForm if 'new_project' in request.POST else ProjectChoiceForm project_form = project_form_class(request.POST) if not tq_form.is_valid(): status = 'error' message = 'Task Queue: %s' % '; '.join( '{} - {}'.format(cap_words(field), ' ,'.join(errors)) for field, errors in tq_form.errors.items()) elif 'new_project' in request.POST and not project_form.is_valid(): status = 'error' message = 'Project: %s' % '; '.join( '{} - {}'.format(cap_words(field), ' ,'.join(errors)) for field, errors in project_form.errors.items()) if status == 'success': document_pks = DocumentCluster.objects.get(pk=request.GET['cluster_pk']) \ .documents.values_list('pk', flat=True) if 'new_task_queue' in request.POST: task_queue = TaskQueue.objects.create( description=request.POST['description']) if 'reviewers' in request.POST: task_queue.reviewers.set(request.POST.getlist('reviewers')) else: task_queue = TaskQueue.objects.get( pk=request.POST['task_queue']) task_queue.documents.add(*document_pks) project = None if 'new_project' in request.POST: project = Project.objects.create( name=request.POST['name'], description=request.POST['project_description']) elif 'project' in request.POST: project = Project.objects.get(pk=request.POST['project']) if project: project.task_queues.add(task_queue) return JsonResponse({ 'message': message, 'status': status }, encoder=DjangoJSONEncoder, safe=False)
def get(self, request, *args, **kwargs): return JsonResponse( { 'task_queue_choice_form': TaskQueueChoiceForm().as_p(), 'task_queue_create_form': TaskQueueForm().as_p(), 'project_choice_form': ProjectChoiceForm().as_p(), 'project_create_form': ProjectForm().as_p() }, encoder=DjangoJSONEncoder, safe=False)