From 334bffdad0b92f5a43a2fbe893bb78bd0198ffc1 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Tue, 4 May 2021 11:54:27 +0200 Subject: [PATCH] automatic generation of mail adress added --- TODO | 2 -- evapp/forms.py | 2 +- .../migrations/0015_remove_employee_email.py | 17 +++++++++++++++++ evapp/models.py | 2 +- evapp/views.py | 19 ++++++++++++------- 5 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 evapp/migrations/0015_remove_employee_email.py diff --git a/TODO b/TODO index fd2a992..d3e74b2 100644 --- a/TODO +++ b/TODO @@ -3,5 +3,3 @@ - in mail ändern "Deine mailadresse" in "ansprechpartner_in" - true/false übersetzen in dataloop - -- automatic generation of MA mail diff --git a/evapp/forms.py b/evapp/forms.py index 46aae25..a7a9a4e 100644 --- a/evapp/forms.py +++ b/evapp/forms.py @@ -29,7 +29,7 @@ class PersonalForm(EvaForm): class Meta: model = Employee - fields = ['usermail', 'firstname', 'lastname', 'intern', 'email', 'department', 'team', ] + fields = ['usermail', 'firstname', 'lastname', 'intern', 'department', 'team', ] class WorkingForm(EvaForm): diff --git a/evapp/migrations/0015_remove_employee_email.py b/evapp/migrations/0015_remove_employee_email.py new file mode 100644 index 0000000..8fcf23f --- /dev/null +++ b/evapp/migrations/0015_remove_employee_email.py @@ -0,0 +1,17 @@ +# Generated by Django 3.1.4 on 2021-05-04 09:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('evapp', '0014_auto_20210504_0842'), + ] + + operations = [ + migrations.RemoveField( + model_name='employee', + name='email', + ), + ] diff --git a/evapp/models.py b/evapp/models.py index 553eec1..79e775d 100644 --- a/evapp/models.py +++ b/evapp/models.py @@ -50,7 +50,7 @@ class Employee(models.Model): firstname = models.CharField(max_length=50, verbose_name="Vorname") lastname = models.CharField(max_length=50, verbose_name="Nachname") intern = models.BooleanField(verbose_name='Interne_r Mitarbeiter_in?', default=True) - email = models.EmailField(max_length=50, verbose_name="E-Mail-Adresse ders Mitarbeitenden") + # email = models.EmailField(max_length=50, verbose_name="E-Mail-Adresse ders Mitarbeitenden") department = models.CharField(max_length=5, choices=DEPARTMENT_CHOICES.items()) team = models.CharField(max_length=20, null=True, blank=True) # TODO? besser als choices? diff --git a/evapp/views.py b/evapp/views.py index 5202f6c..82bd80e 100644 --- a/evapp/views.py +++ b/evapp/views.py @@ -55,18 +55,22 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView): def set_choice(self, c): self.choice = c + def generate_email(self, data): + (first, junk) = data['firstname'].split(maxsplit=1) + (last, junk) = data['lastname'].split(maxsplit=1) + name = first + '.' + last + if not data['intern']: + mail = name + '_ext@wikimedia.de' + else: + mail = name + '@wikimedia.de' + data['email'] = mail def get_all_cleaned_data(self): '''this method deletes data which is only used temporary and is not in the modell, it also changes the mail adress of the employee in some circumstances''' data = super().get_all_cleaned_data() - if not data['intern']: - print("intern employee detected") - (user, domain) = data['email'].split('@') - if not user.endswith('_ext'): - print('add "_ext" to mail adress...') - data['email'] = f'{user}_ext@{domain}' + self.generate_email(data) print("delete CHOICE FROM DATA") if 'choice' in data: @@ -174,6 +178,7 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView): data['accounts'] = [ACCOUNT_CHOICES[c] for c in data['accounts']] # replace keys in data dictionary with verbose_name + mail = data.pop('email') newdata = {self.instance._meta.get_field(k).verbose_name.title() : v for k,v in data.items()} - + newdata['email'] = mail return newdata