Files
old-riskletpy/backend/core/forms.py

69 lines
3.1 KiB
Python
Raw Normal View History

2024-12-29 03:44:52 +01:00
from django import forms
from .models import Organization
class OrganizationForm(forms.ModelForm):
class Meta:
model = Organization
fields = [
'name', 'email', 'employee_headcount', 'annual_revenue', 'critical_applications',
'compliance_frameworks', 'industry_sector', 'it_dependency', 'data_sensitivity',
'network_infrastructure', 'remote_workforce_percentage', 'third_party_vendor_access',
'internal_software_development', 'geographic_scope', 'customer_base', 'customer_type',
2025-09-17 15:24:34 +02:00
'product_portfolio', 'supplier_base', 'it_infrastructure',
'sensitive_data_types', 'integration_level', 'change_rate', 'threat_actors', 'expert_analysis'
2024-12-29 03:44:52 +01:00
]
widgets = {
'compliance_frameworks': forms.CheckboxSelectMultiple(),
'it_infrastructure': forms.CheckboxSelectMultiple(),
'threat_actors': forms.CheckboxSelectMultiple(),
'sensitive_data_types': forms.CheckboxSelectMultiple(),
2024-12-29 03:44:52 +01:00
}
def clean(self):
cleaned_data = super().clean()
# Handle compliance_frameworks "Other"
frameworks = cleaned_data.get('compliance_frameworks', [])
other_framework = self.data.get('compliance_frameworks_other', '').strip()
if 'other' in frameworks and other_framework:
frameworks = [fw for fw in frameworks if fw != 'other']
frameworks.append(other_framework)
cleaned_data['compliance_frameworks'] = frameworks
# Handle industry_sector "Other"
sector = cleaned_data.get('industry_sector')
sector_other = self.data.get('industry_sector_other', '').strip()
if sector == 'other' and sector_other:
cleaned_data['industry_sector'] = sector_other
2025-09-17 15:24:34 +02:00
# Handle Sensitive Data Types & Business Impact
sensitive_data_types = {}
data_types = [
('personal', 'personal_applicable', 'personal_impact'),
('financial', 'financial_applicable', 'financial_impact'),
('ip', 'ip_applicable', 'ip_impact'),
('operational', 'operational_applicable', 'operational_impact'),
('government', 'government_applicable', 'government_impact'),
('none', 'none_applicable', None)
]
for key, applicable_name, impact_name in data_types:
applicable = self.data.get(applicable_name) == 'on'
entry = {'applicable': applicable}
if impact_name:
impact = self.data.get(impact_name)
entry['impact'] = int(impact) if impact and impact.isdigit() else None
sensitive_data_types[key] = entry
cleaned_data['sensitive_data_types'] = sensitive_data_types
return cleaned_data
class GenerateCodesForm(forms.Form):
count = forms.IntegerField(label="How many codes to generate?", min_value=1, max_value=1000)
2025-09-10 21:42:15 +02:00
class ContactForm(forms.Form):
name = forms.CharField(label="Name", max_length=100)
email = forms.EmailField(label="Email")
message = forms.CharField(label="Message", widget=forms.Textarea(attrs={"rows": 6}), max_length=5000)