automatic generation of mail adress added

This commit is contained in:
Benni Bärmann 2021-05-04 11:54:27 +02:00
parent b6c7df541f
commit 334bffdad0
5 changed files with 31 additions and 11 deletions

2
TODO
View File

@ -3,5 +3,3 @@
- in mail ändern "Deine mailadresse" in "ansprechpartner_in" - in mail ändern "Deine mailadresse" in "ansprechpartner_in"
- true/false übersetzen in dataloop - true/false übersetzen in dataloop
- automatic generation of MA mail

View File

@ -29,7 +29,7 @@ class PersonalForm(EvaForm):
class Meta: class Meta:
model = Employee model = Employee
fields = ['usermail', 'firstname', 'lastname', 'intern', 'email', 'department', 'team', ] fields = ['usermail', 'firstname', 'lastname', 'intern', 'department', 'team', ]
class WorkingForm(EvaForm): class WorkingForm(EvaForm):

View File

@ -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',
),
]

View File

@ -50,7 +50,7 @@ class Employee(models.Model):
firstname = models.CharField(max_length=50, verbose_name="Vorname") firstname = models.CharField(max_length=50, verbose_name="Vorname")
lastname = models.CharField(max_length=50, verbose_name="Nachname") lastname = models.CharField(max_length=50, verbose_name="Nachname")
intern = models.BooleanField(verbose_name='Interne_r Mitarbeiter_in?', default=True) 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()) department = models.CharField(max_length=5, choices=DEPARTMENT_CHOICES.items())
team = models.CharField(max_length=20, null=True, blank=True) # TODO? besser als choices? team = models.CharField(max_length=20, null=True, blank=True) # TODO? besser als choices?

View File

@ -55,18 +55,22 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView):
def set_choice(self, c): def set_choice(self, c):
self.choice = 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): def get_all_cleaned_data(self):
'''this method deletes data which is only used temporary and is not in the modell, '''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''' it also changes the mail adress of the employee in some circumstances'''
data = super().get_all_cleaned_data() data = super().get_all_cleaned_data()
if not data['intern']: self.generate_email(data)
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}'
print("delete CHOICE FROM DATA") print("delete CHOICE FROM DATA")
if 'choice' in data: if 'choice' in data:
@ -174,6 +178,7 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView):
data['accounts'] = [ACCOUNT_CHOICES[c] for c in data['accounts']] data['accounts'] = [ACCOUNT_CHOICES[c] for c in data['accounts']]
# replace keys in data dictionary with verbose_name # 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 = {self.instance._meta.get_field(k).verbose_name.title() : v for k,v in data.items()}
newdata['email'] = mail
return newdata return newdata