def updateStudent(request,pk): user = User.objects.get(pk=pk) profile_info = Student.objects.get(user=user) form = UserForm(request.POST or None, instance=user) form_student = StudentProfileForm(request.POST or None, request.FILES or None, instance=profile_info) if all([form.is_valid() and form_student.is_valid()]): form.save() form_student.save() return redirect("education:list") return render(request, 'student_add.html', {'form': form, 'form_student': form_student})
def updateTeacher(request, pk): user = User.objects.get(pk=pk) profile_info = Teacher.objects.get(user=user) form = UserForm(request.POST or None, instance=user) form_teacher = TeacherProfileForm(request.POST or None, request.FILES or None, instance=profile_info) if all([form.is_valid() and form_teacher.is_valid()]): form.save() form_teacher.save() return redirect("education:ogretmen-liste") return render(request, 'Teacher/teacher_add.html', { 'form_user': form, 'form_teacher': form_teacher })
def parent_add(request, student_pk): student = Student.objects.get(pk=student_pk) form_user = UserForm() form_parent = ParentProfileForm() if request.method == 'POST': form_user = UserForm(request.POST) form_parent = ParentProfileForm(request.POST, request.FILES) if form_user.is_valid() and form_parent.is_valid(): group = Group.objects.get(name='Veli') form_user.cleaned_data['groups'] = group user = form_user.save(commit=False) user.set_password("oxit2016") #user.groups.add(group) user.save() group.user_set.add(user) group.save() parent = Parent( user=user, tc=form_parent.cleaned_data['tc'], address=form_parent.cleaned_data['address'], gender=form_parent.cleaned_data['gender'], profileImage=form_parent.cleaned_data['profileImage'], mobilePhone=form_parent.cleaned_data['mobilePhone'], ) parent.save() student.parents.add(parent) student.save() return redirect('education:list') else: messages.warning(request, 'Alanları Kontrol Ediniz') return render(request, 'parent_add.html', { 'form_user': form_user, 'form_parent': form_parent })
def teacher_add(request): form_user = UserForm() form_teacher = TeacherProfileForm() if request.method == 'POST': form_user = UserForm(request.POST) form_teacher = TeacherProfileForm(request.POST, request.FILES) if form_user.is_valid() and form_teacher.is_valid(): group = Group.objects.get(name='Öğretmen') form_user.cleaned_data['groups'] = group user = form_user.save(commit=False) user.set_password("oxit2016") #user.groups.add(group) user.save() group.user_set.add(user) group.save() teacher = Teacher( user=user, tc=form_teacher.cleaned_data['tc'], address=form_teacher.cleaned_data['address'], gender=form_teacher.cleaned_data['gender'], profileImage=form_teacher.cleaned_data['profileImage'], mobilePhone=form_teacher.cleaned_data['mobilePhone'], ) teacher.save() return redirect('education:ogretmen-liste') else: messages.warning(request, 'Alanları Kontrol Ediniz') return render(request, 'Teacher/teacher_add.html', { 'form_user': form_user, 'form_teacher': form_teacher })
def student_add(request): form = UserForm() form_student = StudentProfileForm() if request.method == 'POST': form = UserForm(request.POST) form_student = StudentProfileForm(request.POST, request.FILES) if form.is_valid() and form_student.is_valid(): group = Group.objects.filter(name='Öğrenci') form.cleaned_data['groups'] = group user = form.save(commit=False) user.set_password("oxit2016") # form.cleaned_data['password'] = make_password(form.cleaned_data['password']) user.save() # parent = Parent(user=user2, address=form_student.cleaned_data['address'], profileImage=form_student.cleaned_data['profileImage'], # mobilePhone=form_student.cleaned_data['mobilePhone']) # parent.save() student = Student(user=user, tc=form_student.cleaned_data['tc'], address=form_student.cleaned_data['address'], gender=form_student.cleaned_data['gender'], profileImage=form_student.cleaned_data['profileImage'], mobilePhone=form_student.cleaned_data['mobilePhone'], studentNumber='asasasa',) student= student.save() return redirect('education:list') else: messages.warning(request, 'Alanları Kontrol Ediniz') #messages.add_message(request, messages.INFO, 'Hello world.') return render(request, 'student_add.html', {'form': form, 'form_student': form_student})
def return_add_users(request): perm = general_methods.control_access(request) if not perm: logout(request) return redirect('accounts:login') user_form = UserForm() profile_form = ProfileForm() if request.method == 'POST': x = User.objects.latest('id') data = request.POST.copy() data['username'] = data['email'] user_form = UserForm(data) profile_form = ProfileForm(request.POST, request.FILES) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save(commit=False) group = Group.objects.get(name='Üye') user2 = user_form.save() password = User.objects.make_random_password() user.set_password(password) user2.groups.add(group) user.is_active = True user.save() profil = Profile( user=user, tc=profile_form.cleaned_data['tc'], profileImage=profile_form.cleaned_data['profileImage'], address=profile_form.cleaned_data['address'], gender=profile_form.cleaned_data['gender'], job=profile_form.cleaned_data['job'], city=profile_form.cleaned_data['city'], educationLevel=profile_form.cleaned_data['educationLevel'], mobilePhone=profile_form.cleaned_data['mobilePhone'], birthDate=profile_form.cleaned_data['birthDate'], district=profile_form.cleaned_data['district'], sponsor=profile_form.cleaned_data['sponsor'], iban=profile_form.cleaned_data['iban'], ibanAdSoyad=profile_form.cleaned_data['ibanAdSoyad']) profil.sponsor = profile_form.cleaned_data['sponsor'] profil.isContract = profile_form.cleaned_data['isContract'] profil.isApprove = True profil.isActive = True #sponsorNumber = Profile.objects.filter(sponsor=profile_form.cleaned_data['sponsor']).count() sponsorNumber = Profile.objects.filter( sponsor=profile_form.cleaned_data['sponsor']).filter( isActive=True).count() sp_profile = Profile.objects.get( pk=profile_form.cleaned_data['sponsor'].pk) if sp_profile.user.groups.all()[0].name == 'Admin': limit = 9 else: limit = 2 if sponsorNumber > limit: messages.warning( request, 'Üyeye Sponsor Eklenemez. Sponsor Alanı Dolmuştur.') return redirect('inoks:kullanici-ekle') else: profil.save() subject, from_email, to = 'BAVEN Kullanıcı Giriş Bilgileri', '*****@*****.**', user2.email text_content = 'Aşağıda ki bilgileri kullanarak sisteme giriş yapabilirsiniz.' html_content = '<p> <strong>Site adresi:</strong> <a href="https://network.baven.net">network.baven.net</a></p>' html_content = html_content + '<p><strong>Kullanıcı Adı: </strong>' + user2.username + '</p>' html_content = html_content + '<p><strong>Şifre: </strong>' + password + '</p>' msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) msg.attach_alternative(html_content, "text/html") msg.send() messages.success(request, 'Üye Başarıyla Kayıt Edilmiştir.') return redirect('inoks:kullanici-ekle') else: isExist = general_methods.existMail(data['email']) if isExist: messages.warning( request, 'Mail adresi başka bir üyemiz tarafından kullanılmaktadır.' ) messages.warning(request, 'Alanları Kontrol Ediniz') return render(request, 'kullanici/kullanici-ekle.html', { 'user_form': user_form, 'profile_form': profile_form })