예제 #1
0
파일: views.py 프로젝트: miguel71/SchoolMan
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, ""),
        },
    )
예제 #2
0
파일: views.py 프로젝트: miguel71/SchoolMan
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),
        },
    )