def teacher_class_password_reset(request, access_code): klass = get_object_or_404(Class, access_code=access_code) students = Student.objects.filter(class_field=klass).order_by( "new_user__first_name" ) # check user authorised to see class if request.user.new_teacher != klass.teacher: raise Http404 student_ids = json.loads(request.POST.get("transfer_students", "[]")) students = [ get_object_or_404(Student, id=i, class_field=klass) for i in student_ids ] name_tokens = [] for student in students: password = generate_password(6) name_tokens.append({"name": student.new_user.first_name, "password": password}) student.new_user.set_password(password) student.new_user.save() return render( request, "portal/teach/onboarding_print.html", { "class": klass, "onboarding_done": True, "passwords_reset": True, "name_tokens": name_tokens, "query_data": json.dumps(name_tokens), }, )
def teacher_class_password_reset(request, access_code): klass = get_object_or_404(Class, access_code=access_code) students = Student.objects.filter( class_field=klass).order_by('new_user__first_name') # check user authorised to see class if request.user.new_teacher != klass.teacher: raise Http404 student_ids = json.loads(request.POST.get('transfer_students', '[]')) students = [ get_object_or_404(Student, id=i, class_field=klass) for i in student_ids ] name_tokens = [] for student in students: password = generate_password(6) name_tokens.append({ 'name': student.new_user.first_name, 'password': password }) student.new_user.set_password(password) student.new_user.save() return render( request, 'portal/teach/onboarding_print.html', { 'class': klass, 'onboarding_done': True, 'passwords_reset': True, 'name_tokens': name_tokens, 'query_data': json.dumps(name_tokens) })
def teacher_student_reset(request, pk): """ Reset a student's password """ 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 new_password = generate_password(6) 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), }, )
def process_edit_class(request, access_code, onboarding_done, next_url): """ Handles student creation both during onboarding or on the class page """ klass = get_object_or_404(Class, access_code=access_code) teacher = request.user.new_teacher students = Student.objects.filter(class_field=klass).order_by( "new_user__first_name" ) check_logged_in_students(klass, students) check_user_is_authorised(request, klass) if request.method == "POST": new_students_form = StudentCreationForm(klass, request.POST) if new_students_form.is_valid(): name_tokens = [] for name in new_students_form.strippedNames: password = generate_password(6) name_tokens.append({"name": name, "password": password}) new_student = Student.objects.schoolFactory( klass=klass, name=name, password=password ) give_student_access_to_aimmo_games(student=new_student, new_teacher=teacher) return render( request, "portal/teach/onboarding_print.html", { "class": klass, "name_tokens": name_tokens, "onboarding_done": onboarding_done, "query_data": json.dumps(name_tokens), }, ) else: new_students_form = StudentCreationForm(klass) classes = Class.objects.filter(teacher=teacher) return render( request, next_url, { "class": klass, "classes": classes, "students": students, "new_students_form": new_students_form, "num_students": len(students), }, )
def teacher_student_reset(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 new_password = generate_password(6) 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) })
def teacher_view_class(request, access_code): klass = get_object_or_404(Class, access_code=access_code) teacher = request.user.new_teacher students = Student.objects.filter(class_field=klass).order_by( "new_user__first_name" ) check_logged_in_students(klass, students) check_user_is_authorised(request, klass) if request.method == "POST": new_students_form = StudentCreationForm(klass, request.POST) if new_students_form.is_valid(): name_tokens = [] for name in new_students_form.strippedNames: password = generate_password(6) name_tokens.append({"name": name, "password": password}) Student.objects.schoolFactory(klass=klass, name=name, password=password) return render( request, "portal/teach/onboarding_print.html", { "class": klass, "name_tokens": name_tokens, "onboarding_done": True, "query_data": json.dumps(name_tokens), }, ) else: new_students_form = StudentCreationForm(klass) classes = Class.objects.filter(teacher=teacher) return render( request, "portal/teach/class.html", { "class": klass, "classes": classes, "students": students, "new_students_form": new_students_form, "num_students": len(students), }, )
def teacher_class(request, access_code): klass = get_object_or_404(Class, access_code=access_code) students = Student.objects.filter( class_field=klass).order_by('new_user__first_name') # Check which students are logged in logged_in_students = klass.get_logged_in_students() for student in students: if logged_in_students.filter(id=student.id).exists(): student.logged_in = True else: student.logged_in = False # check user authorised to see class if request.user.new_teacher != klass.teacher: raise Http404 if request.method == 'POST': new_students_form = StudentCreationForm(klass, request.POST) if new_students_form.is_valid(): name_tokens = [] for name in new_students_form.strippedNames: password = generate_password(6) name_tokens.append({'name': name, 'password': password}) Student.objects.schoolFactory(klass=klass, name=name, password=password) return render( request, 'portal/teach/teacher_new_students.html', { 'class': klass, 'name_tokens': name_tokens, 'query_data': json.dumps(name_tokens) }) else: new_students_form = StudentCreationForm(klass) return render( request, 'portal/teach/teacher_class.html', { 'new_students_form': new_students_form, 'class': klass, 'students': students, 'num_students': len(students) })
def teacher_class(request, access_code): klass = get_object_or_404(Class, access_code=access_code) students = Student.objects.filter(class_field=klass).order_by('user__user__first_name') # Check which students are logged in logged_in_students = klass.get_logged_in_students() for student in students: if logged_in_students.filter(id=student.id).exists(): student.logged_in = True else: student.logged_in = False # check user authorised to see class if request.user.userprofile.teacher != klass.teacher: raise Http404 if request.method == 'POST': new_students_form = StudentCreationForm(klass, request.POST) if new_students_form.is_valid(): name_tokens = [] for name in new_students_form.strippedNames: password = generate_password(6) name_tokens.append({'name': name, 'password': password}) Student.objects.schoolFactory( klass=klass, name=name, password=password) return render(request, 'portal/teach/teacher_new_students.html', { 'class': klass, 'name_tokens': name_tokens, 'query_data': json.dumps(name_tokens), }) else: new_students_form = StudentCreationForm(klass) return render(request, 'portal/teach/teacher_class.html', { 'new_students_form': new_students_form, 'class': klass, 'students': students, 'num_students': len(students), })
def teacher_view_class(request, access_code): klass = get_object_or_404(Class, access_code=access_code) teacher = request.user.new_teacher students = Student.objects.filter( class_field=klass).order_by('new_user__first_name') check_logged_in_students(klass, students) check_user_is_authorised(request, klass) if request.method == 'POST': new_students_form = StudentCreationForm(klass, request.POST) if new_students_form.is_valid(): name_tokens = [] for name in new_students_form.strippedNames: password = generate_password(6) name_tokens.append({'name': name, 'password': password}) Student.objects.schoolFactory(klass=klass, name=name, password=password) return render( request, 'portal/teach/onboarding_print.html', { 'class': klass, 'name_tokens': name_tokens, 'onboarding_done': True, 'query_data': json.dumps(name_tokens) }) else: new_students_form = StudentCreationForm(klass) classes = Class.objects.filter(teacher=teacher) return render( request, 'portal/teach/class.html', { 'class': klass, 'classes': classes, 'students': students, 'new_students_form': new_students_form, 'num_students': len(students) })
def teacher_student_reset(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 new_password = generate_password(6) 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) })
def teacher_class_password_reset(request, access_code): klass = get_object_or_404(Class, access_code=access_code) students = Student.objects.filter(class_field=klass).order_by('user__user__first_name') # check user authorised to see class if request.user.userprofile.teacher != klass.teacher: raise Http404 student_ids = json.loads(request.POST.get('transfer_students', '[]')) students = [get_object_or_404(Student, id=i, class_field=klass) for i in student_ids] name_tokens = [] for student in students: password = generate_password(6) name_tokens.append({'name': student.user.user.first_name, 'password': password}) student.user.user.set_password(password) student.user.user.save() return render(request, 'portal/teach/teacher_students_reset.html', {'class': klass, 'name_tokens': name_tokens, 'query_data': json.dumps(name_tokens)})
def teacher_student_reset(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 new_password = generate_password(6) 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), }, )
def teacher_class_password_reset(request, access_code): """ Reset passwords for one or more students """ klass = get_object_or_404(Class, access_code=access_code) students = Student.objects.filter( class_field=klass).order_by("new_user__first_name") # check user authorised to see class if request.user.new_teacher != klass.teacher: raise Http404 student_ids = json.loads(request.POST.get("transfer_students", "[]")) students = [ get_object_or_404(Student, id=i, class_field=klass) for i in student_ids ] name_tokens = [] for student in students: password = generate_password(6) name_tokens.append({ "name": student.new_user.first_name, "password": password }) student.new_user.set_password(password) student.new_user.save() return render( request, "portal/teach/onboarding_print.html", { "class": klass, "onboarding_done": True, "passwords_reset": True, "name_tokens": name_tokens, "query_data": json.dumps(name_tokens), }, )