Ejemplo n.º 1
0
def subject(request):
    try:
        tsubject = get_model_from_id_on_get(TSubject, request)
    except Exception:
        return HttpResponse("Error")

    if not has_permission_in_tsubject(tsubject, request.user.id):
        return HttpResponse("Error, you don't have permission")

    lessons = []
    for lesson in Lesson.objects.filter(tsubject=tsubject).all():
        lessons.append({"text": "", "id": lesson.id})  ##?????????????????????????

    return render(
        request,
        "man/subject.html",
        {
            "tsubject": tsubject,
            "classes_string": classes_many_string(tsubject.associated_classes),
            "lective_year": tsubject.lective_year.identifier,
            "lessons": list_lessons_and_count_from_query_set(Lesson.objects.filter(tsubject=tsubject)),
            "is_teacher": is_teacher_in_tsubject(tsubject, request.user.id),
            "navbar_data": navbar_data(request, ""),
        },
    )
Ejemplo n.º 2
0
def lesson(request, lesson_id):
    # try:
    #    lesson = get_model_from_id_on_get(Lesson, request)
    # except Exception:
    #    return HttpResponse("Error")
    try:
        lesson = Lesson.objects.get(pk=lesson_id)
    except Exception:
        return HttpResponse("Error")
    if not has_permission_in_tsubject(lesson.tsubject, request.user.id):
        return HttpResponse("Error, you don't have permission")

    lesson_nums = get_lesson_start_and_end_num(lesson)
    lesson_start_num = lesson_nums[0]
    lesson_end_num = lesson_nums[1]

    return render(
        request,
        "man/lesson.html",
        {
            "lesson": lesson,
            "date": lesson.datetime.strftime("%d/%m/%Y"),
            "lesson_num_string": create_lesson_string(lesson_start_num, lesson_end_num),
            "lective_times_string": lesson_lective_times_string(lesson).replace("; ", "\n"),
            "navbar_data": navbar_data(request, ""),
        },
    )
Ejemplo n.º 3
0
def lesson_history(request, lesson_id):
    # try:
    #    lesson = get_model_from_id_on_get(Lesson, request)
    # except Exception:
    #    return HttpResponse("Error")
    try:
        lesson = Lesson.objects.get(pk=lesson_id)
    except Exception:
        return HttpResponse("Error")
    if not has_permission_in_tsubject(lesson.tsubject, request.user.id):
        return HttpResponse("Error, you don't have permission")

    lesson_nums = get_lesson_start_and_end_num(lesson)
    lesson_start_num = lesson_nums[0]
    lesson_end_num = lesson_nums[1]

    history_changes = []

    i = 0
    last_history_object = None
    for lesson_history_object in LessonHistory.objects.filter(lesson=lesson).order_by("save_timestamp").all():
        changes_dict = {"change": i}
        differences = lesson_history_object.get_differences(last_history_object)
        changes_dict.update(differences)
        if "date" in changes_dict:
            changes_dict["date"] = changes_dict["date"].strftime("%d/%m/%Y")

        if "lective_times" in changes_dict:
            changes_dict["lective_times"] = lesson_lective_times_string(lesson).replace("; ", "\n")

        history_changes.append(changes_dict)
        i += 1
        last_history_object = lesson_history_object

    return render(
        request,
        "man/lesson_history.html",
        {
            "lesson": lesson,
            "date": lesson.datetime.strftime("%d/%m/%Y"),
            "lesson_num_string": create_lesson_string(lesson_start_num, lesson_end_num),
            "navbar_data": navbar_data(request, ""),
            "history_changes": reversed(history_changes),
        },
    )