vielleicht ja so

This commit is contained in:
holger.trampe 2019-12-12 23:50:47 +01:00
parent 220827c17d
commit 62151c5f03
4 changed files with 15 additions and 26 deletions

View File

@ -8,15 +8,13 @@ from django.contrib.auth.models import Permission
@receiver(post_save, sender=User) @receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs): def create_profile(sender, instance, created, **kwargs):
if created: if created:
user_agency = User.objects.filter(profile__agency__pk=instance.agency.pk) Profile.objects.create(user=instance, agency=instance.agency, parent=instance.parent)
if(len(user_agency)) == 1:
Profile.objects.create(user=instance, agency=instance.agency)
''' '''
Wenn ein neuer Nutzer angelegt wird und dies der erste der Agentur ist, Wenn ein neuer Nutzer angelegt wird und dies der erste der Agentur ist,
erhält dieser automatisch alle verfügbaren Rechte! erhält dieser automatisch alle verfügbaren Rechte!
''' '''
user_agency = User.objects.filter(profile__agency__pk=instance.agency.pk)
if len(user_agency) == 1: if len(user_agency) == 1:
tempuser = user_agency[0] tempuser = user_agency[0]
temprof = Profile temprof = Profile
@ -24,17 +22,7 @@ def create_profile(sender, instance, created, **kwargs):
tempperm = Permission.objects.get(codename=ele[0]) tempperm = Permission.objects.get(codename=ele[0])
tempuser.user_permissions.add(tempperm) tempuser.user_permissions.add(tempperm)
tempuser.profile.func = 'lead' tempuser.profile.func = 'lead'
tempuser.profile.parent = tempuser
tempuser.save() tempuser.save()
else:
Profile.objects.create(user=instance, agency=instance.agency, parent=instance.parent)
user_agency = User.objects.filter(profile__agency__pk=instance.agency.pk)
tempuser.profile.func = 'external'
tempuser.profile.parent=parent
tempuser.profile.agency=agency
tempuser.profile.user = user
tempuser.save()
@receiver(post_save, sender=User) @receiver(post_save, sender=User)
def save_profile(sender, instance, **kwargs): def save_profile(sender, instance, **kwargs):

View File

@ -45,6 +45,7 @@ class AgencyCreateView(CreateView):
agency.save() agency.save()
newuser_name = form.cleaned_data.get('first_name') + ' ' + form.cleaned_data.get('last_name') newuser_name = form.cleaned_data.get('first_name') + ' ' + form.cleaned_data.get('last_name')
form.instance.agency = agency form.instance.agency = agency
form.instance.parent = None
msg_html = render_to_string('users/register_mail.html', {'username': newuser_name}) msg_html = render_to_string('users/register_mail.html', {'username': newuser_name})
# E-Mail für Passwort-Setzung! # E-Mail für Passwort-Setzung!
send_mail( send_mail(