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

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

View File

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