def teacher_edit_student(request, pk): student = get_object_or_404(Student, id=pk) # check user is authorised to edit student if request.user.new_teacher != student.class_field.teacher: raise Http404 name_form = TeacherEditStudentForm( student, initial={'name': student.new_user.first_name}) password_form = TeacherSetStudentPass() if request.method == 'POST': if 'update_details' in request.POST: name_form = TeacherEditStudentForm(student, request.POST) if name_form.is_valid(): name = name_form.cleaned_data['name'] student.new_user.first_name = name student.new_user.save() student.save() messages.success( request, "The student's details have been changed successfully.") elif 'set_password' in request.POST: password_form = TeacherSetStudentPass(request.POST) if password_form.is_valid(): # check not default value for CharField new_password = password_form.cleaned_data['password'] if (new_password != ''): student.new_user.set_password(new_password) student.new_user.save() name_pass = [{ 'name': student.new_user.first_name, 'password': new_password }] return render( request, 'portal/teach/teacher_student_reset.html', { 'student': student, 'class': student.class_field, 'password': new_password, 'query_data': json.dumps(name_pass) }) return render( request, 'portal/teach/teacher_edit_student.html', { 'name_form': name_form, 'password_form': password_form, 'student': student, 'class': student.class_field, })
def teacher_edit_student(request, pk): student = get_object_or_404(Student, id=pk) # check user is authorised to edit student if request.user.userprofile.teacher != student.class_field.teacher: raise Http404 name_form = TeacherEditStudentForm(student, initial={"name": student.user.user.first_name}) password_form = TeacherSetStudentPass() if request.method == "POST": if "update_details" in request.POST: name_form = TeacherEditStudentForm(student, request.POST) if name_form.is_valid(): name = name_form.cleaned_data["name"] student.user.user.first_name = name student.user.user.save() student.save() messages.success(request, "The student's details have been changed successfully.") elif "set_password" in request.POST: password_form = TeacherSetStudentPass(request.POST) if password_form.is_valid(): # check not default value for CharField new_password = password_form.cleaned_data["password"] if new_password != "": student.user.user.set_password(new_password) student.user.user.save() name_pass = [{"name": student.user.user.first_name, "password": new_password}] return render( request, "portal/teach/teacher_student_reset.html", { "student": student, "class": student.class_field, "password": new_password, "query_data": json.dumps(name_pass), }, ) return render( request, "portal/teach/teacher_edit_student.html", {"name_form": name_form, "password_form": password_form, "student": student, "class": student.class_field}, )
def teacher_edit_student(request, pk): student = get_object_or_404(Student, id=pk) # check user is authorised to edit student if request.user.userprofile.teacher != student.class_field.teacher: raise Http404 name_form = TeacherEditStudentForm(student, initial={ 'name': student.user.user.first_name }) password_form = TeacherSetStudentPass() if request.method == 'POST': if 'update_details' in request.POST: name_form = TeacherEditStudentForm(student, request.POST) if name_form.is_valid(): name = name_form.cleaned_data['name'] student.user.user.first_name = name student.user.user.save() student.save() messages.success(request, "The student's details have been changed successfully.") elif 'set_password' in request.POST: password_form = TeacherSetStudentPass(request.POST) if password_form.is_valid(): # check not default value for CharField new_password = password_form.cleaned_data['password'] if (new_password != ''): student.user.user.set_password(new_password) student.user.user.save() name_pass = [{'name': student.user.user.first_name, 'password': new_password}] return render(request, 'portal/teach/teacher_student_reset.html', {'student': student, 'class': student.class_field, 'password': new_password, 'query_data': json.dumps(name_pass)}) return render(request, 'portal/teach/teacher_edit_student.html', { 'name_form': name_form, 'password_form': password_form, 'student': student, 'class': student.class_field, })
def teacher_edit_student(request, pk): """ Changing a student's details """ student = get_object_or_404(Student, id=pk) check_if_reset_authorised(request, student) name_form = TeacherEditStudentForm( student, initial={"name": student.new_user.first_name} ) password_form = TeacherSetStudentPass() set_password_mode = False if request.method == "POST": if "update_details" in request.POST: name_form = TeacherEditStudentForm(student, request.POST) if name_form.is_valid(): name = name_form.cleaned_data["name"] student.new_user.first_name = name student.new_user.save() student.save() messages.success( request, "The student's details have been changed successfully." ) else: password_form = TeacherSetStudentPass(request.POST) if password_form.is_valid(): return process_reset_password_form(request, student, password_form) set_password_mode = True return render( request, "portal/teach/teacher_edit_student.html", { "name_form": name_form, "password_form": password_form, "student": student, "class": student.class_field, "set_password_mode": set_password_mode, }, )
def teacher_edit_student(request, pk): student = get_object_or_404(Student, id=pk) check_if_reset_authorised(request, student) name_form = TeacherEditStudentForm( student, initial={"name": student.new_user.first_name} ) password_form = TeacherSetStudentPass() set_password_mode = False if request.method == "POST": if "update_details" in request.POST: name_form = TeacherEditStudentForm(student, request.POST) if name_form.is_valid(): name = name_form.cleaned_data["name"] student.new_user.first_name = name student.new_user.save() student.save() messages.success( request, "The student's details have been changed successfully." ) else: password_form = TeacherSetStudentPass(request.POST) if password_form.is_valid(): return process_reset_password_form(request, student, password_form) set_password_mode = True return render( request, "portal/teach/teacher_edit_student.html", { "name_form": name_form, "password_form": password_form, "student": student, "class": student.class_field, "set_password_mode": set_password_mode, }, )
def teacher_edit_student(request, pk): student = get_object_or_404(Student, id=pk) check_if_reset_authorised(request, student) name_form = TeacherEditStudentForm( student, initial={'name': student.new_user.first_name}) password_form = TeacherSetStudentPass() set_password_mode = False if request.method == 'POST': if 'update_details' in request.POST: name_form = TeacherEditStudentForm(student, request.POST) if name_form.is_valid(): name = name_form.cleaned_data['name'] student.new_user.first_name = name student.new_user.save() student.save() messages.success( request, "The student's details have been changed successfully.") else: password_form = TeacherSetStudentPass(request.POST) if password_form.is_valid(): return process_reset_password_form(request, student, password_form) set_password_mode = True return render( request, 'portal/teach/teacher_edit_student.html', { 'name_form': name_form, 'password_form': password_form, 'student': student, 'class': student.class_field, 'set_password_mode': set_password_mode, })