예제 #1
0
파일: views.py 프로젝트: miguel71/SchoolMan
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, ""),
        },
    )
예제 #2
0
파일: views.py 프로젝트: miguel71/SchoolMan
def neweditlesson(request):
    print("A")
    error_message = None
    if request.method == "POST":
        print("B")
        # submitting
        from funcs.submit import new_edit_lesson_submit

        try:
            lesson = new_edit_lesson_submit(request)
            return redirect("man:lesson", lesson_id=lesson.id)
        except (KeyError):
            error_message = "Request was missing parameters"
            return HttpResponse(error_message)

    editing_lesson = None
    edit_id = request.GET.get("edit", None)
    if edit_id is not None:
        edit_id = int(edit_id)
        editing_lesson = Lesson.objects.get(pk=edit_id)
        tsubject = editing_lesson.tsubject
    else:
        try:
            tsubject = get_model_from_id_on_get(TSubject, request)
        except Exception:
            print(":?")
            return HttpResponse("Error")

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

    editing_lectivetime_ids = []
    if editing_lesson:
        for lective_time in editing_lesson.lective_times.all():
            editing_lectivetime_ids.append(lective_time.id)

    return render(
        request,
        "man/newlesson.html",
        {
            "tsubject": tsubject,
            "editing_lesson": editing_lesson,
            "editing_lectivetime_ids": editing_lectivetime_ids,
            "classes_string": classes_many_string(tsubject.associated_classes),
            "lective_year": tsubject.lective_year.identifier,
            "lective_times": LectiveTime.objects.order_by("startTime").all(),
            "error_message": error_message,
            "navbar_data": navbar_data(request, ""),
        },
    )
예제 #3
0
파일: views.py 프로젝트: miguel71/SchoolMan
def b_newlesson(request):
    try:
        tsubject = get_model_from_id_on_get(TSubject, request)
    except Exception:
        return HttpResponse("Error")

    if not is_teacher_in_tsubject(tsubject, request.user.id):
        return HttpResponse("Error, you don't have permission")
    form = NewLessonForm()  # An unbound form

    return render(
        request,
        "man/newlesson.html",
        {
            "tsubject": tsubject,
            "classes_string": classes_many_string(tsubject.associated_classes),
            "lective_year": tsubject.lective_year.identifier,
            "lective_times": LectiveTime.objects.order_by("startTime").all(),
            "form": form,
        },
    )