Skip to content

Commit

Permalink
Add fake incident form
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Feb 14, 2024
1 parent adcb1e8 commit ad042a0
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/argus/incident/forms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django import forms
from django.core.exceptions import ValidationError
from django.forms import modelform_factory

from argus.auth.models import User
from .models import SourceSystem
from .models import Incident, SourceSystem, Tag


class AddSourceSystemForm(forms.ModelForm):
Expand Down Expand Up @@ -49,3 +50,34 @@ def save(self, commit=True):
instance.save()

return instance


class FakeIncidentForm(forms.ModelForm):
stateful = forms.BooleanField(initial=True)
tags = forms.CharField(label="Tags (comma separated of form key=value)")

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for field in self.fields.values():
field.required = False

class Meta:
model = Incident
fields = [
"stateful",
"description",
"level",
"tags",
]

def clean_tags(self):
tags = self.cleaned_data["tags"]
if tags:
tag_list = tags.split(",")
for tag in tag_list:
try:
Tag.split(tag=tag)
except (ValueError, ValidationError) as e:
raise forms.ValidationError(str(e))
tags = tag_list
return tags

0 comments on commit ad042a0

Please sign in to comment.