def add_task(request, incident_id): """add task to incident """ if request.method == 'POST': try: inc = Incident.objects.get(id=incident_id) except Incident.DoesNotExist: messages.error(request, 'The requested incident does not exist!') return render(request, 'kraut_incident/incident_list.html', context) task_dict = slicedict(request.POST, 'TaskCheckBox') for key in task_dict: task_id = int(task_dict[key]) try: tt = TemplateTask.objects.get(id=task_id) template = {"name": tt.name, "description": tt.description} t = Task(**template) t.save() inc.tasks.add(t) except: messages.error( request, 'Failed getting incident task with ID: %s' % (task_id)) return HttpResponseRedirect( reverse("incidents:view_incident", kwargs={'incident_id': incident_id})) messages.info(request, 'Task "%s" added' % (t.name)) inc.save() return HttpResponseRedirect( reverse("incidents:view_incident", kwargs={'incident_id': incident_id}))
def add_contact_incident(request, incident_id): """add incident contact to incident """ if request.method == 'POST': try: inc = Incident.objects.get(id=incident_id) except Incident.DoesNotExist: messages.error(request, 'The requested incident does not exist!') return render(request, 'kraut_incident/incident_list.html', context) co_dict = slicedict(request.POST, 'ContactCheckBox') for key in co_dict: co_id = int(co_dict[key]) try: co = Contact.objects.get(id=co_id) inc.contacts.add(co) except Contact.DoesNotExist: messages.error( request, 'Failed getting incident contact with ID: %s' % (co_id)) return HttpResponseRedirect( reverse("incidents:view_incident", kwargs={'incident_id': incident_id})) inc.save() return HttpResponseRedirect( reverse("incidents:view_incident", kwargs={'incident_id': incident_id}))
def add_handler_incident(request, incident_id): """add incident handler to incident """ if request.method == 'POST': try: inc = Incident.objects.get(id=incident_id) except Incident.DoesNotExist: messages.error(request, 'The requested incident does not exist!') return render(request, 'kraut_incident/incident_list.html', context) handler_dict = slicedict(request.POST, 'HandlerCheckBox') for key in handler_dict: handler_id = int(handler_dict[key]) try: ih = Handler.objects.get(id=handler_id) inc.incident_handler.add(ih) except Handler.DoesNotExist: messages.error( request, 'Failed getting incident handler with ID: %s' % (handler_id)) return HttpResponseRedirect( reverse("incidents:view_incident", kwargs={'incident_id': incident_id})) inc.save() return HttpResponseRedirect( reverse("incidents:view_incident", kwargs={'incident_id': incident_id}))
def new_incident(request): context = {} if request.method == 'POST': ### {'status': <Incident_Status: Open>, 'incident_number': 4976401221, 'category': <Incident_Category: Investigation>, 'description': u'', 'title': u'Unnamed Incident'} incident_form = IncidentForm(request.POST) if incident_form.is_valid(): # check if handler and contact given handler_dict = slicedict(request.POST, 'HandlerCheckBox') contact_dict = slicedict(request.POST, 'ContactCheckBox') if len(handler_dict)<=0: messages.error(request, 'Missing an incident handler!') return HttpResponseRedirect(reverse("incidents:new")) if len(contact_dict)<=0: messages.error(request, 'Missing an incident contact!') return HttpResponseRedirect(reverse("incidents:new")) new_incident = Incident( incident_number = incident_form.cleaned_data['incident_number'], title = incident_form.cleaned_data['title'], description = incident_form.cleaned_data['description'], status = incident_form.cleaned_data['status'], category = incident_form.cleaned_data['category'] ) new_incident.save() for key in handler_dict: handler_id = handler_dict[key] try: handler = Handler.objects.get(pk=handler_id) new_incident.incident_handler.add(handler) except Handler.DoesNotExist: messages.error(request, 'Failed getting incident handler with ID: %s' % (handler_id)) for key in contact_dict: contact_id = contact_dict[key] try: contact = Contact.objects.get(pk=contact_id) new_incident.contacts.add(contact) except Contact.DoesNotExist: messages.error(request, 'Failed getting incident contact with ID: %s' % (contact_id)) new_incident.save() messages.info(request, "Incident successfully created!") return HttpResponseRedirect(reverse("incidents:new")) incident_form = IncidentForm(initial={'status': 1, 'category': 7}) contact_form = ContactForm() handler_form = HandlerForm() context['formset'] = incident_form context['contact_form'] = contact_form context['handler_form'] = handler_form return render_to_response('kraut_incident/new.html', context, context_instance=RequestContext(request))
def new_incident(request): context = {} if request.method == 'POST': ### {'status': <Incident_Status: Open>, 'incident_number': 4976401221, 'category': <Incident_Category: Investigation>, 'description': u'', 'title': u'Unnamed Incident'} incident_form = IncidentForm(request.POST) if incident_form.is_valid(): # check if handler and contact given handler_dict = slicedict(request.POST, 'HandlerCheckBox') contact_dict = slicedict(request.POST, 'ContactCheckBox') if len(handler_dict) <= 0: messages.error(request, 'Missing an incident handler!') return HttpResponseRedirect(reverse("incidents:new")) if len(contact_dict) <= 0: messages.error(request, 'Missing an incident contact!') return HttpResponseRedirect(reverse("incidents:new")) new_incident = Incident( incident_number=incident_form.cleaned_data['incident_number'], title=incident_form.cleaned_data['title'], description=incident_form.cleaned_data['description'], status=incident_form.cleaned_data['status'], category=incident_form.cleaned_data['category'], severity=incident_form.cleaned_data['severity']) new_incident.save() for key in handler_dict: handler_id = handler_dict[key] try: handler = Handler.objects.get(pk=handler_id) new_incident.incident_handler.add(handler) except Handler.DoesNotExist: messages.error( request, 'Failed getting incident handler with ID: %s' % (handler_id)) for key in contact_dict: contact_id = contact_dict[key] try: contact = Contact.objects.get(pk=contact_id) new_incident.contacts.add(contact) except Contact.DoesNotExist: messages.error( request, 'Failed getting incident contact with ID: %s' % (contact_id)) new_incident.save() messages.info(request, "Incident successfully created!") return HttpResponseRedirect(reverse("incidents:new")) incident_form = IncidentForm(initial={'status': 1, 'category': 7}) contact_form = ContactForm() handler_form = HandlerForm() context['formset'] = incident_form context['contact_form'] = contact_form context['handler_form'] = handler_form if hasattr(request.user.userextension, 'namespaces'): context['usernamespace'] = request.user.userextension.namespaces.last( ).namespace.split(':')[0] context['namespaceicon'] = get_icon_for_namespace( request.user.userextension.namespaces.last().namespace) else: context['usernamespace'] = 'nospace' context['namespaceicon'] = static('ns_icon/octalpus.png') return render(request, 'kraut_incident/incident_new.html', context)