예제 #1
0
def teacher_dismiss_students(request, access_code):
    klass = get_object_or_404(Class, access_code=access_code)

    # check user is authorised to deal with class
    if request.user.new_teacher != klass.teacher:
        raise Http404

    # get student objects for students to be deleted, confirming they are in the class
    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
    ]

    TeacherDismissStudentsFormSet = formset_factory(
        wraps(TeacherDismissStudentsForm)(partial(TeacherDismissStudentsForm)),
        extra=0,
        formset=BaseTeacherDismissStudentsFormSet)

    if request.method == 'POST' and 'submit_dismiss' in request.POST:
        formset = TeacherDismissStudentsFormSet(request.POST)
        if formset.is_valid():
            for data in formset.cleaned_data:
                student = get_object_or_404(
                    Student,
                    class_field=klass,
                    new_user__first_name__iexact=data['orig_name'])
                student.class_field = None
                student.new_user.first_name = data['name']
                student.new_user.username = data['name']
                student.new_user.email = data['email']
                student.save()
                student.new_user.save()

                send_verification_email(request, student.new_user)

            messages.success(
                request,
                'The students have been removed successfully from the class.')
            return HttpResponseRedirect(
                reverse_lazy('teacher_class',
                             kwargs={'access_code': access_code}))
    else:
        initial_data = [{
            'orig_name':
            student.new_user.first_name,
            'name':
            generate_new_student_name(student.new_user.first_name),
            'email':
            ''
        } for student in students]

        formset = TeacherDismissStudentsFormSet(initial=initial_data)

    return render(request, 'portal/teach/teacher_dismiss_students.html', {
        'formset': formset,
        'class': klass,
        'students': students
    })
예제 #2
0
def teacher_dismiss_students(request, access_code):
    klass = get_object_or_404(Class, access_code=access_code)

    # check user is authorised to deal with class
    if request.user.userprofile.teacher != klass.teacher:
        raise Http404

    # get student objects for students to be deleted, confirming they are in the class
    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]

    TeacherDismissStudentsFormSet = formset_factory(
        wraps(TeacherDismissStudentsForm)(partial(TeacherDismissStudentsForm)),
        extra=0,
        formset=BaseTeacherDismissStudentsFormSet,
    )

    if request.method == "POST" and "submit_dismiss" in request.POST:
        formset = TeacherDismissStudentsFormSet(request.POST)
        if formset.is_valid():
            for data in formset.cleaned_data:
                student = get_object_or_404(
                    Student, class_field=klass, user__user__first_name__iexact=data["orig_name"]
                )
                student.class_field = None
                student.user.awaiting_email_verification = True
                student.user.user.first_name = data["name"]
                student.user.user.username = data["name"]
                student.user.user.email = data["email"]
                student.save()
                student.user.save()
                student.user.user.save()

                send_verification_email(request, student.user)

            messages.success(request, "The students have been removed successfully from the class.")
            return HttpResponseRedirect(reverse_lazy("teacher_class", kwargs={"access_code": access_code}))
    else:
        initial_data = [
            {
                "orig_name": student.user.user.first_name,
                "name": generate_new_student_name(student.user.user.first_name),
                "email": "",
            }
            for student in students
        ]

        formset = TeacherDismissStudentsFormSet(initial=initial_data)

    return render(
        request,
        "portal/teach/teacher_dismiss_students.html",
        {"formset": formset, "class": klass, "students": students},
    )
예제 #3
0
def teacher_dismiss_students(request, access_code):
    """
    Dismiss a student (make them independent)
    """
    klass = get_object_or_404(Class, access_code=access_code)

    check_if_dismiss_authorised(request, klass)

    # get student objects for students to be dismissed, confirming they are in the class
    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
    ]

    TeacherDismissStudentsFormSet = formset_factory(
        wraps(TeacherDismissStudentsForm)(partial(TeacherDismissStudentsForm)),
        extra=0,
        formset=BaseTeacherDismissStudentsFormSet,
    )

    if is_right_dismiss_form(request):
        formset = TeacherDismissStudentsFormSet(request.POST)
        if formset.is_valid():
            return process_dismiss_student_form(request, formset, klass,
                                                access_code)

    else:
        initial_data = [{
            "orig_name":
            student.new_user.first_name,
            "name":
            generate_new_student_name(student.new_user.first_name),
            "email":
            "",
        } for student in students]

        formset = TeacherDismissStudentsFormSet(initial=initial_data)

    return render(
        request,
        "portal/teach/teacher_dismiss_students.html",
        {
            "formset": formset,
            "class": klass,
            "students": students
        },
    )
예제 #4
0
def teacher_dismiss_students(request, access_code):
    klass = get_object_or_404(Class, access_code=access_code)

    # check user is authorised to deal with class
    if request.user.userprofile.teacher != klass.teacher:
        raise Http404

    # get student objects for students to be deleted, confirming they are in the class
    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]

    TeacherDismissStudentsFormSet = formset_factory(wraps(TeacherDismissStudentsForm)(partial(TeacherDismissStudentsForm)), extra=0, formset=BaseTeacherDismissStudentsFormSet)

    if request.method == 'POST' and 'submit_dismiss' in request.POST:
        formset = TeacherDismissStudentsFormSet(request.POST)
        if formset.is_valid():
            for data in formset.cleaned_data:
                student = get_object_or_404(Student, class_field=klass, user__user__first_name__iexact=data['orig_name'])
                student.class_field = None
                student.user.awaiting_email_verification = True
                student.user.user.first_name = data['name']
                student.user.user.username = data['name']
                student.user.user.email = data['email']
                student.save()
                student.user.save()
                student.user.user.save()

                send_verification_email(request, student.user)

            messages.success(request, 'The students have been removed successfully from the class.')
            return HttpResponseRedirect(reverse_lazy('teacher_class', kwargs={'access_code': access_code }))
    else:
        initial_data = [{'orig_name' : student.user.user.first_name,
                         'name' : generate_new_student_name(student.user.user.first_name),
                         'email' : '',
                        } for student in students]

        formset = TeacherDismissStudentsFormSet(initial=initial_data)

    return render(request, 'portal/teach/teacher_dismiss_students.html', {
        'formset': formset,
        'class': klass,
        'students': students,
    })
예제 #5
0
def teacher_dismiss_students(request, access_code):
    klass = get_object_or_404(Class, access_code=access_code)

    check_if_dismiss_authorised(request, klass)

    # get student objects for students to be deleted, confirming they are in the class
    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
    ]

    TeacherDismissStudentsFormSet = formset_factory(
        wraps(TeacherDismissStudentsForm)(partial(TeacherDismissStudentsForm)),
        extra=0,
        formset=BaseTeacherDismissStudentsFormSet)

    if is_right_dismiss_form(request):
        formset = TeacherDismissStudentsFormSet(request.POST)
        if formset.is_valid():
            return process_dismiss_student_form(request, formset, klass,
                                                access_code)

    else:
        initial_data = [{
            'orig_name':
            student.new_user.first_name,
            'name':
            generate_new_student_name(student.new_user.first_name),
            'email':
            ''
        } for student in students]

        formset = TeacherDismissStudentsFormSet(initial=initial_data)

    return render(request, 'portal/teach/teacher_dismiss_students.html', {
        'formset': formset,
        'class': klass,
        'students': students
    })
예제 #6
0
def teacher_dismiss_students(request, access_code):
    klass = get_object_or_404(Class, access_code=access_code)

    check_if_dismiss_authorised(request, klass)

    # get student objects for students to be deleted, confirming they are in the class
    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
    ]

    TeacherDismissStudentsFormSet = formset_factory(
        wraps(TeacherDismissStudentsForm)(partial(TeacherDismissStudentsForm)),
        extra=0,
        formset=BaseTeacherDismissStudentsFormSet,
    )

    if is_right_dismiss_form(request):
        formset = TeacherDismissStudentsFormSet(request.POST)
        if formset.is_valid():
            return process_dismiss_student_form(request, formset, klass, access_code)

    else:
        initial_data = [
            {
                "orig_name": student.new_user.first_name,
                "name": generate_new_student_name(student.new_user.first_name),
                "email": "",
            }
            for student in students
        ]

        formset = TeacherDismissStudentsFormSet(initial=initial_data)

    return render(
        request,
        "portal/teach/teacher_dismiss_students.html",
        {"formset": formset, "class": klass, "students": students},
    )