def for_student(student_id, date_from = None, date_to = None): """ Retrives lessons for student filtered by date Keyword arguments: student_id - int ID of a student date_from - date in iso format string (!) or None (default: None) date_to - date in iso format string (!) or None (default: None) """ # Check if student exists try: Student.get_by_id(student_id) except Student.DoesNotExist: raise NoSuchDBRecordException("Student with id {} does not exist in database".format(student_id)) query = (Lesson .select(Lesson.name, Lesson.start, Lesson.end, Lesson.date, Room.name, Room.address, Group.name) .join(Group) .join(StudentToGroup) .join(Student) .switch(Lesson) .join(Room) .switch(Lesson) .where(Student.id == student_id) .order_by(Lesson.date, Lesson.start) ) if date_from != None: query = query.where(Lesson.date > date.fromisoformat(date_from)) if date_to != None: query = query.where(Lesson.date < date.fromisoformat(date_to)) return query_to_json_mapper(query)
def lessons_students(student_id): return render_template('lessons/student.html', student=Student.get_by_id(student_id))