snapshot: preserve integrations controls and status UX cleanup

This commit is contained in:
Md Bayazid Bostame
2026-03-26 00:06:43 +01:00
parent 197bd3c226
commit e0231a6cca
15 changed files with 1591 additions and 392 deletions

View File

@@ -1,9 +1,11 @@
from django import forms
from pathlib import Path
from django.utils.translation import get_language
from datetime import timedelta
from django.utils import timezone
from django.utils.translation import get_language, gettext as _
from .form_builder import apply_form_field_config
from .models import EmployeeProfile, FormOption, OffboardingRequest, OnboardingRequest
from .models import EmployeeProfile, FormOption, OffboardingRequest, OnboardingRequest, WorkflowConfig
YES_NO_CHOICES = [('', '--'), ('ja', 'Ja'), ('nein', 'Nein')]
@@ -222,6 +224,11 @@ class OnboardingRequestForm(forms.ModelForm):
self.requester_email = (kwargs.pop('requester_email', '') or '').strip().lower()
super().__init__(*args, **kwargs)
config = WorkflowConfig.objects.order_by('id').first()
self.handover_lead_days = max(0, int(getattr(config, 'device_handover_lead_days', 5) or 5))
minimum_handover_date = timezone.localdate() + timedelta(days=self.handover_lead_days)
self.fields['handover_date'].widget.attrs['min'] = minimum_handover_date.isoformat()
self.fields['full_name'].label = 'Name'
full_name_initial = (self.initial.get('full_name') or '').strip()
if full_name_initial and not self.initial.get('first_name') and not self.initial.get('last_name'):
@@ -322,6 +329,18 @@ class OnboardingRequestForm(forms.ModelForm):
if has('successor_name') and cleaned.get('successor_required_choice') == 'ja' and not cleaned.get('successor_name'):
self.add_error('successor_name', 'Bitte Name der Vorgängerperson eintragen.')
handover_date = cleaned.get('handover_date')
if has('handover_date') and handover_date:
minimum_date = timezone.localdate() + timedelta(days=getattr(self, 'handover_lead_days', 5))
if handover_date < minimum_date:
self.add_error(
'handover_date',
_('Das Übergabedatum muss mindestens %(days)s Tage in der Zukunft liegen (frühestens %(date)s).') % {
'days': getattr(self, 'handover_lead_days', 5),
'date': minimum_date.strftime('%Y-%m-%d'),
},
)
return cleaned
def save(self, commit=True):