def new_engagement(request): if request.method == 'POST': form = EngForm2(request.POST) if form.is_valid(): new_eng = form.save() new_eng.lead = request.user new_eng.save() tags = request.POST.getlist('tags') t = ", ".join(tags) new_eng.tags = t messages.add_message(request, messages.SUCCESS, 'Engagement added successfully.', extra_tags='alert-success') if "_Add Tests" in request.POST: return HttpResponseRedirect( reverse('add_tests', args=(new_eng.id, ))) else: return HttpResponseRedirect( reverse('view_engagement', args=(new_eng.id, ))) else: form = EngForm2() add_breadcrumb(title="New Engagement", top_level=False, request=request) return render(request, 'dojo/new_eng.html', { 'form': form, })
def edit_engagement(request, eid): eng = Engagement.objects.get(pk=eid) jform = None if request.method == 'POST': form = EngForm2(request.POST, instance=eng) if 'jiraform-push_to_jira' in request.POST: jform = JIRAFindingForm(request.POST, prefix='jiraform', enabled=True) if form.is_valid(): if 'jiraform-push_to_jira' in request.POST: try: jissue = JIRA_Issue.objects.get(engagement=eng) update_epic_task.delay( eng, jform.cleaned_data.get('push_to_jira')) enabled = True except: enabled = False add_epic_task.delay(eng, jform.cleaned_data.get('push_to_jira')) pass form.save() tags = request.POST.getlist('tags') t = ", ".join(tags) eng.tags = t messages.add_message(request, messages.SUCCESS, 'Engagement updated successfully.', extra_tags='alert-success') if '_Add Tests' in request.POST: return HttpResponseRedirect( reverse('add_tests', args=(eng.id, ))) else: return HttpResponseRedirect( reverse('view_engagement', args=(eng.id, ))) else: form = EngForm2(instance=eng) try: jissue = JIRA_Issue.objects.get(engagement=eng) enabled = True except: enabled = False pass if get_system_setting('enable_jira') and JIRA_PKey.objects.filter( product=eng.product).count() != 0: jform = JIRAFindingForm(prefix='jiraform', enabled=enabled) else: jform = None form.initial['tags'] = [tag.name for tag in eng.tags] add_breadcrumb(parent=eng, title="Edit Engagement", top_level=False, request=request) return render(request, 'dojo/new_eng.html', { 'form': form, 'edit': True, 'jform': jform })
def edit_engagement(request, eid): eng = Engagement.objects.get(pk=eid) if request.method == 'POST': form = EngForm2(request.POST, instance=eng) if form.is_valid(): form.save() tags = request.POST.getlist('tags') t = ", ".join(tags) eng.tags = t messages.add_message(request, messages.SUCCESS, 'Engagement updated successfully.', extra_tags='alert-success') if '_Add Tests' in request.POST: return HttpResponseRedirect( reverse('add_tests', args=(eng.id, ))) else: return HttpResponseRedirect( reverse('view_engagement', args=(eng.id, ))) else: form = EngForm2(instance=eng) form.initial['tags'] = [tag.name for tag in eng.tags] add_breadcrumb(parent=eng, title="Edit Engagement", top_level=False, request=request) return render(request, 'dojo/new_eng.html', { 'form': form, 'edit': True, })