def register_students(user, students):
    # school = School.objects.get(user_id=school_id)
    if len(students) > 1:
        print("AAAAAAA")
        for student in students:
            if len(student) > 0:
                print("BBBBB")
                if student[0] != "No":
                    print("CCCCCC")
                    if len(student) < 4:
                        print("DDDDDD")
                        i = len(student)
                        while i < 4:
                            student.append("")
                            i += 1
                    print("EEEEE")
                    try:
                        print("FFFFFF")
                        s, _ = User.objects.get_or_create(
                            username=student[1],
                            first_name=student[2],
                            last_name=student[3],
                            email=student[4],
                            phone=student[5])

                        s.account_type = 'student'
                        Group.objects.get_or_create(name="Students")
                        user_group = Group.objects.get(name='Students')
                        password = User.objects.make_random_password()
                        s.set_password(password)
                        print(password)
                        file = open('student.txt', 'a')
                        file.write("{:<20}{:>10}\n".format(
                            s.username, password))
                        file.close()
                        user_send_mail.delay(user=s,
                                             password=password,
                                             host=user.email)
                        # send_mail('Account Password', 'UserName: {}\n'
                        #                               'First Name: {}\n'
                        #                               'Last Name: {}\n'
                        #                               'Password for your account is {}'
                        #                               ''.format(s.username, s.first_name, s.last_name,
                        #                                         password),
                        #           request.user.email,
                        #           [s.email])
                        s.save()
                        user_group.user_set.add(s)
                        SchoolStudent.objects.get_or_create(
                            user=s, school=user.school_profile)
                    except IntegrityError:
                        pass
Beispiel #2
0
 def save(self, commit=True):
     user = super(MarketerSchoolSignUpForm, self).save(commit=False)
     user.account_type = 'school'
     Group.objects.get_or_create(name="Schools")
     user_group = Group.objects.get(name="Schools")
     password = User.objects.make_random_password()
     user.set_password(password)
     # print(password)
     # file = open('school.txt', 'a')
     # file.write("{:<20}{:>10}\n".format(user.username, password))
     # file.close()
     user_send_mail.delay(user=user, password=password)
     # send_mail('Account Password', 'UserName: {}\n'
     #                               'Password for your account is {}'
     #                               ''.format(user.username, password),
     #           settings.EMAIL_HOST_USER,
     #           [user.email])
     user.save()
     user_group.user_set.add(user)
     return user
Beispiel #3
0
 def save(self, commit=True):
     user = super(CuratorSignUpForm, self).save(commit=False)
     user.account_type = 'curator'
     # Group.objects.get_or_create(name="Curator")
     # user_group = Group.objects.get(name="Curator")
     password = User.objects.make_random_password()
     user.set_password(password)
     # print(password)
     user.save()
     CuratorGroup(user)
     # file = open('curator.txt', 'a')
     # file.write("{:<20}{:>10}\n".format(user.username, password))
     # file.close()
     user_send_mail.delay(user=user, password=password)
     # send_mail('Account Password', 'UserName: {}\n'
     #                               'First Name: {}\n'
     #                               'Last Name: {}\n'
     #                               'Password for your account is {}'
     #                               ''.format(user.username, user.first_name, user.last_name, password),
     #           settings.EMAIL_HOST_USER,
     #           [user.email])
     # user_group.user_set.add(user)
     return user
Beispiel #4
0
 def save(self, request, commit=True):
     user = super(StudentSignUpForm, self).save(commit=False)
     user.account_type = 'student'
     Group.objects.get_or_create(name="Students")
     user_group = Group.objects.get(name='Students')
     password = User.objects.make_random_password()
     user.set_password(password)
     # print(password)
     # file = open('student.txt', 'a')
     # file.write("{:<20}{:>10}\n".format(user.username, password))
     # file.close()
     user_send_mail.delay(user=user,
                          password=password,
                          host=request.user.email)
     # send_mail('Account Password', 'UserName: {}\n'
     #                               'First Name: {}\n'
     #                               'Last Name: {}\n'
     #                               'Password for your account is {}'
     #                               ''.format(user.username, user.first_name, user.last_name, password),
     #           request.user.email,
     #           [user.email])
     user.save()
     user_group.user_set.add(user)
     return user