snapshot: preserve custom field parity across forms timeline and pdf
This commit is contained in:
@@ -7,7 +7,7 @@ from django.utils import timezone
|
||||
from django.utils.translation import get_language, gettext as _, gettext_lazy
|
||||
|
||||
from .branding import get_company_email_domain
|
||||
from .form_builder import apply_form_field_config
|
||||
from .form_builder import add_custom_form_fields, apply_form_field_config, custom_field_key_from_name, hidden_custom_field_names, is_custom_field_name
|
||||
from .models import EmployeeProfile, FormOption, OffboardingRequest, OnboardingRequest, PortalBranding, PortalCompanyConfig, PortalTrialConfig, UserProfile, WorkflowConfig
|
||||
from .roles import ROLE_ADMIN, ROLE_GROUP_NAMES, ROLE_IT_STAFF, ROLE_LABELS, ROLE_PLATFORM_OWNER, ROLE_STAFF, ROLE_SUPER_ADMIN, assign_user_role, user_has_capability
|
||||
from .totp import normalize_recovery_code, normalize_totp_token, verify_totp_token
|
||||
@@ -814,6 +814,7 @@ class OnboardingRequestForm(forms.ModelForm):
|
||||
self.fields['needed_resources_multi'].choices = self._choices_from_options('resource', RESOURCE_CHOICES)
|
||||
self.fields['signature_image'].required = False
|
||||
apply_form_field_config('onboarding', self)
|
||||
add_custom_form_fields('onboarding', self, getattr(self.instance, 'custom_field_values', None))
|
||||
|
||||
def clean_work_email(self):
|
||||
value = (self.cleaned_data.get('work_email') or '').strip().lower()
|
||||
@@ -883,6 +884,11 @@ class OnboardingRequestForm(forms.ModelForm):
|
||||
},
|
||||
)
|
||||
|
||||
hidden_custom = hidden_custom_field_names('onboarding', cleaned)
|
||||
for field_name in hidden_custom:
|
||||
cleaned[field_name] = False if self.fields.get(field_name) and self.fields[field_name].widget.input_type == 'checkbox' else ''
|
||||
self._errors.pop(field_name, None)
|
||||
|
||||
return cleaned
|
||||
|
||||
def save(self, commit=True):
|
||||
@@ -922,6 +928,11 @@ class OnboardingRequestForm(forms.ModelForm):
|
||||
|
||||
instance.agreement = 'accepted' if self.cleaned_data.get('agreement_confirm') else ''
|
||||
instance.onboarded_by_email = self.requester_email
|
||||
instance.custom_field_values = {
|
||||
custom_field_key_from_name(name): self.cleaned_data.get(name)
|
||||
for name in self.fields.keys()
|
||||
if is_custom_field_name(name)
|
||||
}
|
||||
|
||||
if commit:
|
||||
instance.save()
|
||||
@@ -962,6 +973,7 @@ class OffboardingRequestForm(forms.ModelForm):
|
||||
self.fields['department'].initial = prefill_profile.department
|
||||
self.fields['job_title'].initial = prefill_profile.job_title
|
||||
apply_form_field_config('offboarding', self)
|
||||
add_custom_form_fields('offboarding', self, getattr(self.instance, 'custom_field_values', None))
|
||||
|
||||
def clean_work_email(self):
|
||||
value = (self.cleaned_data.get('work_email') or '').strip().lower()
|
||||
@@ -971,3 +983,16 @@ class OffboardingRequestForm(forms.ModelForm):
|
||||
if self.email_domain and not value.endswith(expected_suffix):
|
||||
raise forms.ValidationError(_('Bitte verwenden Sie eine @%(domain)s E-Mail-Adresse.') % {'domain': self.email_domain})
|
||||
return value
|
||||
|
||||
def save(self, commit=True):
|
||||
instance = super().save(commit=False)
|
||||
if not (instance.preferred_language or '').strip():
|
||||
instance.preferred_language = (get_language() or 'de').split('-')[0]
|
||||
instance.custom_field_values = {
|
||||
custom_field_key_from_name(name): self.cleaned_data.get(name)
|
||||
for name in self.fields.keys()
|
||||
if is_custom_field_name(name)
|
||||
}
|
||||
if commit:
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
Reference in New Issue
Block a user