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 new_edit_lesson_submit(request): editing = request.POST['editing'] if editing is None: #new lesson tsubject = request.POST['tsubject'] else: #editing lesson editing = int(editing) editing_lesson = Lesson.objects.get(pk=editing) if editing_lesson is None: raise Exception("Invalid id") tsubject = editing_lesson.tsubject if not is_teacher_in_tsubject(tsubject, request.user.id): return HttpResponse("Error, you don't have permission") summary = request.POST['summary'] date = request.POST['date'] num_times = request.POST['numtimes'] lective_time_ids = request.POST['lectivetimeids'].split(';') if len(lective_time_ids) is 0: return HttpResponse("Error") lectivetime_list = [] for lective_time_id in lective_time_ids: lectivetime_list.append(LectiveTime.objects.get(pk=int(lective_time_id))) lectivetime_list = sorted(lectivetime_list, key=attrgetter('startTime', 'endTime')) # The client sorts it but we should also do it(the client might heve done it wrong and we shouldn't relly on it) import pytz utc=pytz.UTC date_time = utc.localize(datetime.fromtimestamp(float(date)/1000.)) date_time = date_time.replace(hour=lectivetime_list[0].startTime.hour, minute=lectivetime_list[0].startTime.minute, second=0, microsecond=0) if editing is None: #new lesson for file in request.FILES.getlist('files'): upload_file = UploadFile(orig_file=file) upload_file.save() lesson = Lesson.objects.create_lesson(tsubject, summary, date_time, num_times, lectivetime_list); lesson.save() return lesson else: #editing lesson editing_lesson.summary = summary editing_lesson.date_time = date_time editing_lesson.num_times = num_times editing_lesson.lectivetime_list = lectivetime_list editing_lesson.save() return editing_lesson
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 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 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, }, )