From 3953149e2ff26461eae47238d5689edf1d9a89ce Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Tue, 9 Feb 2021 12:45:33 +0100 Subject: [PATCH] add validation: desk must be present if not remote working --- eva/settings.py | 2 +- evapp/forms.py | 10 +++++++++- evapp/models.py | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/eva/settings.py b/eva/settings.py index 3b869b3..c2de6d1 100644 --- a/eva/settings.py +++ b/eva/settings.py @@ -25,7 +25,7 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' SECRET_KEY = 'g%+i6+gkwt3zz@+k-5x1dtstuw4)&qd$lxd^bt2oswy5e1#dul' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True STATIC_ROOT = BASE_DIR / 'staticfiles' diff --git a/evapp/forms.py b/evapp/forms.py index 4b95ab4..266b958 100644 --- a/evapp/forms.py +++ b/evapp/forms.py @@ -1,5 +1,6 @@ from django.db import models from django.forms import ModelForm, DateInput, Form, ChoiceField, RadioSelect +from django.core.exceptions import ValidationError from .models import Employee @@ -30,10 +31,17 @@ class PersonalForm(EvaForm): fields = ['firstname', 'lastname', 'intern', 'email', 'department', 'team', ] class WorkingForm(EvaForm): + + def clean(self): + data = self.cleaned_data + if not data['remote'] and data['desk'] is None: + raise ValidationError('Wer nicht remote arbeitet braucht einen Schreibtisch!') + return data + class Meta: model = Employee fields = ['firstdate_employment', 'firstdate_presence', 'jobdescription_german', - 'jobdescription_english', 'desk',] + 'jobdescription_english', 'remote', 'desk',] widgets = {'firstdate_employment': DateInput(attrs={'type': 'date'}), 'firstdate_presence': DateInput(attrs={'type': 'date'}),} diff --git a/evapp/models.py b/evapp/models.py index 626d08c..91f0e22 100644 --- a/evapp/models.py +++ b/evapp/models.py @@ -55,8 +55,8 @@ class Employee(models.Model): firstdate_presence = models.DateField(null=True, verbose_name="erster Tag der Anwesenheit in der Geschäftsstelle") jobdescription_german = models.CharField(null=True, max_length=100, verbose_name="Stellenbeschreibung(deutsch)") jobdescription_english = models.CharField(null=True, max_length=100, verbose_name="job description(english)") - desk = models.CharField(max_length=100, null=True, verbose_name="Wo soll der Arbeitsplatz sein?") - # TODO: we need an optional question for remote work here + remote = models.BooleanField(verbose_name='Braucht keinen Arbeitsplatz weil Home-Office', default=False) + desk = models.CharField(max_length=100, null=True, blank=True, verbose_name="Wo soll der Arbeitsplatz sein?") # IT related stuff laptop = models.CharField(max_length=2, choices=LAPTOP_CHOICES.items(), default='14')