Beispiel #1
0
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_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),
        },
    )
Beispiel #3
0
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),
    })
Beispiel #5
0
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)
        })