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, ""), }, )
def get_lesson_nums_string(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") numlessons = int(request.GET.get("numlessons", None)) start_end_lesson_nums = get_lesson_start_and_end_num_not_created_yet( tsubject, int(request.GET.get("time", None)), numlessons, int(request.GET.get("ignore", None)) ) return HttpResponse(create_lesson_string(start_end_lesson_nums[0], start_end_lesson_nums[1]))
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), }, )