def test_analystmemo_note_form_filled(self): """ test minimum form requirements / INVALID """ # get object form = AnalystmemoForm(data={'analystmemo_note': 'lorem ipsum'}) # compare self.assertFalse(form.is_valid())
def test_analystmemo_form_empty(self): """ test minimum form requirements / INVALID """ # get object form = AnalystmemoForm(data={}) # compare self.assertFalse(form.is_valid())
def test_analystmemo_system_form_filled(self): """ test minimum form requirements / VALID """ # get foreign key object id system_id = System.objects.get(system_name='system_1').system_id # get object form = AnalystmemoForm(data={ 'analystmemo_note': 'lorem ipsum', 'system': system_id, }) # compare self.assertTrue(form.is_valid())
def analystmemos_edit(request, pk): analystmemo = get_object_or_404(Analystmemo, pk=pk) if request.method == 'POST': form = AnalystmemoForm(request.POST, instance=analystmemo) if form.is_valid(): analystmemo = form.save(commit=False) analystmemo.analystmemo_modified_by_user_id = request.user analystmemo.save() analystmemo.logger(str(request.user), " ANALYSTMEMO_EDIT_EXECUTED") messages.success(request, 'Analystmemo edited') return redirect('/systems/' + str(analystmemo.system.system_id)) else: form = AnalystmemoForm(instance=analystmemo) analystmemo.logger(str(request.user), " ANALYSTMEMO_EDIT_ENTERED") return render(request, 'dfirtrack_main/analystmemo/analystmemos_edit.html', {'form': form})
def analystmemos_add(request): if request.method == 'POST': form = AnalystmemoForm(request.POST) if form.is_valid(): analystmemo = form.save(commit=False) analystmemo.analystmemo_created_by_user_id = request.user analystmemo.analystmemo_modified_by_user_id = request.user analystmemo.save() analystmemo.logger(str(request.user), " ANALYSTMEMO_ADD_EXECUTED") messages.success(request, 'Analystmemo added') return redirect('/systems/' + str(analystmemo.system.system_id)) else: if request.method == 'GET' and 'system' in request.GET: system = request.GET['system'] form = AnalystmemoForm(initial={ 'system': system, }) else: form = AnalystmemoForm() debug_logger(str(request.user), " ANALYSTMEMO_ADD_ENTERED") return render(request, 'dfirtrack_main/analystmemo/analystmemos_add.html', {'form': form})