def add_note(): """ Renders the VMS teacher notes page and note history _OR_ Creates a new lesson note if the note form is valid, the session adds the note to the note table """ if not request.form: teacher = crud.get_teacher_by_id(session['teacher_id']) teacher_notes = teacher.notes return render_template('teacher-notes.html', teacher=teacher, teacher_notes=teacher_notes) note_teacher_id = (session['teacher_id']) student_id = request.form.get('note_student_name') note_date = request.form.get('note_date') note_time = request.form.get('note_time') note_content = request.form.get('note_content') # Combine date and time to parse provided objects into a datetime object note_created_at = datetime.strptime(note_date + ' ' + note_time, '%Y-%m-%d %H:%M') note = crud.create_note(note_teacher_id, student_id, note_created_at, note_content) return jsonify({'status': 'ok', 'note_date': note.note_created_at})
def view_student_logs(): """Renders page for viewing past logs for individual student""" student = crud.get_student_by_id(session['student_id']) teacher = crud.get_teacher_by_id(session["teacher_id"]) return render_template('charts.html', student=student, teacher=teacher)
def go_to_student_profile(student_id): """ Allows a teacher to see each of their students's profile page""" teacher = crud.get_teacher_by_id(session['teacher_id']) student = crud.get_student_by_id(student_id) return render_template('student-profile.html', student=student, teacher=teacher)
def view_teacher_profile(): """Renders the profile page for the teacher in session""" if 'teacher_id' not in session: return jsonify({'error': 'No teacher_id in session. Please log in!'}) teacher = crud.get_teacher_by_id(session['teacher_id']) return render_template('teacher-profile.html', teacher=teacher)
def view_teacher_notes(): """Renders the VMS teacher notes page and note history""" teacher = crud.get_teacher_by_id(session['teacher_id']) teacher_notes = teacher.notes # teacher_notes = crud.get_notes_by_teacher_id(teacher.teacher_id) return render_template('teacher-notes.html', teacher=teacher, teacher_notes=teacher_notes)
def seed_chart_three(student_id): """ Passes data for minutes practiced over four weeks to chart #3 as JSON""" if 'student_id' in session: pass elif 'teacher_id' in session: teacher = crud.get_teacher_by_id(session['teacher_id']) valid_students = teacher.get_student_ids() # print('****' * 5, student_id, '****' * 5, sep='\n') if int(student_id or 0) in valid_students: crud.get_logs_by_student_id else: return jsonify({'error': 'student not valid'}) # x-axis data: dates in month (eventually divded into four weeks) dates_in_month = [ ] # holds todays date and previous 27 dates as list items date = datetime.now() for _ in range(28): dater = str(date.year) + '-' + str(date.month) + '-' + str( date.day) #formats each date dates_in_month.append( dater) #adds formatted date to dates_in_month list date = date - timedelta(days=1) #goes back a day from current date minutes_practiced = [] # format_date = datetime.strptime(date, "%Y-%m-%d").date() # y-axis data: minutes practiced on each date in the month for date in dates_in_month: # loops over the dates of the month monthly_dates = crud.search_logs_by_date( datetime.strptime(date, '%Y-%m-%d').date(), student_id) #finds and formatts all logged practice dates in DB if monthly_dates: minutes_practiced.append((date, monthly_dates.minutes_practiced)) else: minutes_practiced.append((date, 0)) data = {} data['dates_in_month'] = [ datetime.strptime(date, '%Y-%m-%d').date().ctime()[4:10] for date, date_prac in minutes_practiced ] #['2021-3-1', '2021-2-28', '2021-2-27', '2021-2-26', '2021-2-25', '2021-2-24', '2021-2-23', '2021-2-22', '2021-2-21', '2021-2-20', '2021-2-19', '2021-2-18', '2021-2-17', '2021-2-16', '2021-2-15', '2021-2-14', '2021-2-13', '2021-2-12', '2021-2-11', '2021-2-10', '2021-2-9', '2021-2-8', '2021-2-7', '2021-2-6', '2021-2-5', '2021-2-4', '2021-2-3', '2021-2-2'] data['minutes_practiced'] = [ min_prac for date, min_prac in minutes_practiced ] # [('2021-3-1', 45), ('2021-2-28', 0), ('2021-2-27', 0), ('2021-2-26', 120), ('2021-2-25', 12), ('2021-2-24', 45), ('2021-2-23', 35), ('2021-2-22', 100), ('2021-2-21', 22), ('2021-2-20', 0), ('2021-2-19', 45), ('2021-2-18', 22), ('2021-2-17', 23), ('2021-2-16', 45), ('2021-2-15', 0), ('2021-2-14', 10), ('2021-2-13', 0), ('2021-2-12', 72), ('2021-2-11', 0), ('2021-2-10', 42), ('2021-2-9', 0), ('2021-2-8', 50), ('2021-2-7', 65), ('2021-2-6', 35), ('2021-2-5', 122), ('2021-2-4', 40), ('2021-2-3', 25), ('2021-2-2', 0)] return jsonify(data)
def go_to_student_logs(student_id): """ Lets a teacher see each of their students's practice log history and data""" teacher = crud.get_teacher_by_id(session['teacher_id']) student = crud.get_student_by_id(student_id) # Get the student's logs through the relationship student_logs = student.logs return render_template('charts.html', student=student, teacher=teacher, student_logs=student_logs)
def seed_chart_two(student_id): """ Passes data for days practiced over four weeks to chart #2 as JSON""" if 'student_id' in session: pass elif 'teacher_id' in session: teacher = crud.get_teacher_by_id(session['teacher_id']) valid_students = teacher.get_student_ids() if int(student_id or 0) in valid_students: crud.get_logs_by_student_id(int(student_id)) else: return jsonify({'error': 'student not valid'}) # x-axis data: dates in month (eventually divded into four weeks) dates_in_month = [ ] # holds todays date and previous 27 dates as list items date = datetime.now() for _ in range(28): dater = str(date.year) + '-' + str(date.month) + '-' + str( date.day) #formats each date dates_in_month.append( dater) #adds formatted date to dates_in_month list date = date - timedelta(days=1) #changed log_date = [] # y-axis data: days practiced in each week of the month for date in dates_in_month: # loops over each date of the month monthly_dates = crud.search_logs_by_date( datetime.strptime(date, '%Y-%m-%d').date(), student_id) #finds and formatts all logged practice dates in DB if monthly_dates: log_date.append( (date, 1) ) #adds to log_date date in month, 1 to signify a practice session that date else: log_date.append( (date, 0) ) #adds date in month, 0 to signify no practice session that date data = {} data['dates_in_month'] = [ datetime.strptime(date, '%Y-%m-%d').date().ctime()[4:10] for date, date_prac in log_date ] data['log_date'] = [date_prac for date, date_prac in log_date] return jsonify(data)
def list_logs_by_student(student_id): """Lists every log made by a student depending on their student_id.""" student = crud.get_student_by_id(student_id) student_logs = student.logs if "teacher_id" in session: teacher = crud.get_teacher_by_id(session["teacher_id"]) else: teacher = None return render_template('charts.html', student=student, teacher=teacher, student_logs=student_logs)
def view_teacher_profile(): """Renders the profile page for the teacher in session""" teacher = crud.get_teacher_by_id(session['teacher_id']) return render_template('teacher-profile.html', teacher=teacher)