def studentSignUpView(request): error_msg = "" if (request.method == 'POST'): form = forms.StudentSignUpForm(request.POST) if (form.is_valid()): print(form.cleaned_data['email']) instance = form.save(commit=False) # Only after instance is saved We can access id instance.save() # Creating Profile Instance for the new user as student profileInstance = models.Profile(is_student=True) profileInstance.save() old_user = User.objects.filter(username=form.cleaned_data['email']) if (old_user): error_msg = "User with specified Email Id Already Exists" else: user = User(username=form.cleaned_data['email']) user.set_password(form.cleaned_data['password']) user.save() user = authenticate(request, username=form.cleaned_data['email'], password=form.cleaned_data['password']) if (user): login(request, user) return HttpResponseRedirect(reverse('student:home')) else: form = forms.StudentSignUpForm() return render(request, 'accounts/student/signup.html', { "form": form, "error_msg": error_msg })
def signUpView(request): # Checking If the User is already Logged In if (request.user.is_authenticated): checkAndRedirect(request.user) if (request.method == 'POST'): form = forms.SignUpForm(request.POST) if (form.is_valid()): # print() instance = form.save(commit=False) # Only after instance is saved We can access id instance.save() # Creating Profile Instance for the new user profileInstance = models.Profile(user=instance) profileInstance.save() # Creating Customer Instance for the new user customerInstance = Customer(user=instance) customerInstance.save() user = authenticate(request, username=form.cleaned_data['username'], password=form.cleaned_data['password1']) if (user): login(request, user) return HttpResponseRedirect(reverse('customer:landing')) else: form = forms.SignUpForm() context = { 'form': form, 'cartc': 0, } return render(request, 'accounts/signup.html', context)
def handle(self, *args, **options): students_per_section = options['students_per_section'] sections = structure_models.Section.objects.all().select_related( 'grade') year = '19' count = 0 for s in sections: students = [] student_infos = [] for i in range(students_per_section): username = get_username(year, count) count += 1 s_user = models.User(username=username) s_user.set_password('student1234') students.append(s_user) info = models.StudentInfo(gr_number=username, section_id=s.id) student_infos.append(info) # Create users models.User.objects.bulk_create(students) # Create infos models.StudentInfo.objects.bulk_create(student_infos) # Create profiles students = models.User.objects.all().order_by( '-id')[:students_per_section] student_infos = models.StudentInfo.objects.all().order_by( '-id')[:students_per_section] profiles = [] for student, info in zip(students, student_infos): profile = models.Profile(user_id=student.id, profile_type=models.Profile.STUDENT, student_info=info, fullname=student.username) profiles.append(profile) models.Profile.objects.bulk_create(profiles) self.stdout.write( f'Created {students_per_section} students per section.')
def create_user(self): validated_data = self.validated_data user = models.User( username=validated_data['fullname'].replace(' ', '')) user.set_password(validated_data['fullname'].replace(' ', '')) user.is_active = True user.save() # Create student info info = models.StaffInfo( date_hired=validated_data['date_hired'], address=validated_data['address'], gender=validated_data['gender'], ) info.save() # Create profile profile = models.Profile( user_id=user.id, fullname=validated_data['fullname'], contact=validated_data['contact'], staff_info_id=info.id, profile_type=validated_data['profile_type'], ) profile.save()
def create_user(self): validated_data = self.validated_data user = models.User(username=validated_data['gr_number']) user.set_password(validated_data['gr_number']) user.is_active = True user.save() # Create student info info = models.StudentInfo( gr_number=validated_data['gr_number'], section_id=validated_data['section_id'], date_enrolled=validated_data['date_enrolled'], date_of_birth=validated_data['date_of_birth'], address=validated_data['address'], guardian_name=validated_data['guardian_name'], guardian_contact=validated_data['guardian_contact'], gender=validated_data['gender']) info.save() # Create profile profile = models.Profile(user_id=user.id, fullname=validated_data['fullname'], student_info_id=info.id, profile_type=models.Profile.STUDENT) profile.save()
def companySignUpView(request): if (request.user.is_authenticated): return HttpResponseRedirect(reverse('home')) error_msg = "" if (request.method == 'POST'): form = forms.CompanySignUpForm(request.POST) if (form.is_valid()): print(form.cleaned_data['email']) instance = form.save(commit=False) old_user = User.objects.filter(username=form.cleaned_data['email']) if (old_user): error_msg = "User with specified Email Id Already Exists" else: user = User(username=form.cleaned_data['email']) user.set_password(form.cleaned_data['password']) user.save() # Creating Profile Instance for the new user as student profileInstance = models.Profile(is_student=False) profileInstance.user = user profileInstance.save() # Adding user mapping to companyProfile instance.user = user instance.save() user = authenticate(request, username=form.cleaned_data['email'], password=form.cleaned_data['password']) if (user): login(request, user) message = "You are successfully registered" return HttpResponseRedirect(reverse('company:profile')) else: form = forms.CompanySignUpForm() return render(request, 'accounts/company/signup.html', { "form": form, "error_msg": error_msg })