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 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, ""), }, )
def subjects(request): tsubjects_as_student = TSubject.objects.filter(Q(students=request.user.id)) tsubjects_as_teacher = TSubject.objects.filter(Q(teachers=request.user.id)) if tsubjects_as_teacher: subjects_as_student_title = "Subjects as Student" else: subjects_as_student_title = "Subjects" if tsubjects_as_student: subjects_as_teacher_title = "Subjects as Teacher" else: subjects_as_teacher_title = "Subjects" tsubjects_as_student_organized_by_class = organize_tsubjects_by_classes(tsubjects_as_student) tsubjects_as_teacher_organized_by_class = organize_tsubjects_by_classes(tsubjects_as_teacher) return render( request, "man/subjects.html", { "tsubjects_as_student": tsubjects_as_student, "tsubjects_as_teacher": tsubjects_as_teacher, "subjects_as_student_title": subjects_as_student_title, "subjects_as_teacher_title": subjects_as_teacher_title, "tsubjects_as_student_organized_by_class": tsubjects_as_student_organized_by_class, "tsubjects_as_teacher_organized_by_class": tsubjects_as_teacher_organized_by_class, "navbar_data": navbar_data(request, "subjects"), }, )
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, ""), }, )
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), }, )
def index(request): if request.user.is_authenticated(): return render(request, "man/loggedinindex.html", {"navbar_data": navbar_data(request, "")}) else: # return render(request, 'man/anonindex.html') return redirect("man:login")