2025-09-10 13:44:03 +02:00
|
|
|
from django import forms
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from .models import Risk, Control, Incident, ResidualRisk
|
|
|
|
|
2025-09-12 13:04:04 +02:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Base form for status field (DRY for Risk/Control/Incident)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
class BaseStatusForm(forms.ModelForm):
|
|
|
|
"""Abstract base form for models with a 'status' field."""
|
2025-09-10 13:44:03 +02:00
|
|
|
class Meta:
|
|
|
|
fields = ["status"]
|
|
|
|
labels = {"status": _("Status")}
|
|
|
|
widgets = {"status": forms.Select(attrs={"class": "select"})}
|
|
|
|
|
2025-09-12 13:04:04 +02:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# RiskStatusForm
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
class RiskStatusForm(BaseStatusForm):
|
|
|
|
class Meta(BaseStatusForm.Meta):
|
|
|
|
model = Risk
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# ControlStatusForm
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
class ControlStatusForm(BaseStatusForm):
|
|
|
|
class Meta(BaseStatusForm.Meta):
|
2025-09-10 13:44:03 +02:00
|
|
|
model = Control
|
|
|
|
|
2025-09-12 13:04:04 +02:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# IncidentStatusForm
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
class IncidentStatusForm(BaseStatusForm):
|
|
|
|
class Meta(BaseStatusForm.Meta):
|
2025-09-10 13:44:03 +02:00
|
|
|
model = Incident
|
|
|
|
|
2025-09-12 13:04:04 +02:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# ResidualReviewForm
|
|
|
|
# ---------------------------------------------------------------------------
|
2025-09-10 13:44:03 +02:00
|
|
|
class ResidualReviewForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = ResidualRisk
|
|
|
|
fields = ["review_required"]
|
|
|
|
labels = {"review_required": _("Review required")}
|
2025-09-12 13:04:04 +02:00
|
|
|
widgets = {"review_required": forms.CheckboxInput(attrs={"class": "checkbox"})}
|