automatic generation of mail adress added
This commit is contained in:
parent
b6c7df541f
commit
334bffdad0
2
TODO
2
TODO
|
@ -3,5 +3,3 @@
|
|||
- in mail ändern "Deine mailadresse" in "ansprechpartner_in"
|
||||
|
||||
- true/false übersetzen in dataloop
|
||||
|
||||
- automatic generation of MA mail
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
|
@ -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',
|
||||
),
|
||||
]
|
|
@ -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?
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue