def students(): form = SearchForm() if request.method == 'POST' and form.validate(): filteredStudents = Students.search(form.choice.data, form.search.data) students = filteredStudents if filteredStudents is False: flash('Search Error! "{}" does not exist on our list or you have the wrong category'.format( form.search.data), category='danger') return redirect(url_for('students')) return render_template('display_students.html', form=form, filtered=students, students="") else: students = Students.all() return render_template('display_students.html', form=form, students=students, filtered="")
def students(): form = SearchForm() if request.method == 'POST' and form.validate(): filteredStudents = Students.search(form.choice.data, form.search.data) students = filteredStudents return render_template('display_students.html', form=form, filtered=students, students="") else: students = Students.all() return render_template('display_students.html', form=form, students=students, filtered="")
def edit_student(student_id): form = StudentForm() db = Students(idNum=student_id) student = db.search('idNum', student_id) if request.method == 'POST' and form.validate(): newId = Students(idNum=form.id_number.data) if(newId.exist() and student_id != form.id_number.data): flash('ID number already taken please choose another ID NUMBER', category='danger') return redirect(url_for('edit_student', student_id=db.idNum)) else: db.update(form.firstname.data, form.lastname.data, form.gender.data, form.id_number.data, form.course.data) flash('Successfully Edited Student', category='success') return redirect(url_for('students')) else: for attribute in student: form.firstname.data = attribute[0] form.lastname.data = attribute[1] form.gender.data = attribute[2] form.id_number.data = attribute[3] form.course.data = attribute[4] return render_template('edit_student.html', form=form)