def new_teacher(): form = TeacherForm() if request.method == 'POST': if not form.validate(): return render_template('teacher_form.html', form=form, form_name="New teacher", action="new_teacher") else: new_teacher = user_datastore.create_user( username=form.username.data, password=form.password.data, name=form.name.data, surname=form.surname.data, email=form.email.data, birthday = form.bithday.data, subject = form.subject.data, hobby = form.hobby.data, # photo = form.photo.data, position = form.position.data, proglanguage = form.proglanguage.data, specialization = form.specialization.data, title = form.title.data, works = form.works.data) role = db.session.query(ormRole).filter(ormRole.name == "User").one() new_teacher.roles.append(role) db.session.add(new_teacher) db.session.commit() return redirect(url_for('teacher')) return render_template('teacher_form.html', form=form, form_name="New teacher", action="new_teacher")
def edit_teacher(): form = TeacherForm() if request.method == 'GET': teacher_id = request.args.get('teacher_id') db = PostgresDb() teacher_obj = db.sqlalchemy_session.query(Teacher).filter(Teacher.teacher_id == teacher_id).one() # fill form and send to user form.teacher_id.data = teacher_obj.teacher_id form.teacher_faculty.data = teacher_obj.teach_faculty form.teacher_name.data = teacher_obj.teach_name return render_template('teacher_form.html', form=form, form_name="Edit teacher", action="edit_teacher") else: if not form.validate(): return render_template('teacher_form.html', form=form, form_name="Edit teacher", action="edit_teacher") else: db = PostgresDb() # find professor teacher_obj = db.sqlalchemy_session.query(Teacher).filter(Teacher.teacher_id == form.teacher_id.data).one() # update fields from form data teacher_obj.teacher_id = form.teacher_id.data teacher_obj.teach_faculty = form.teacher_faculty.data teacher_obj.teach_name = form.teacher_name.data db.sqlalchemy_session.commit() return redirect(url_for('index_teacher'))
def new_teacher(): if login.isLogged: if login.isAdmin: form = TeacherForm() if request.method == 'POST': if not form.validate(): return render_template('teacher_form.html', form=form, form_name="New teacher", action="new_teacher") else: teacher_obj = Teacher(name=form.name.data, degree=form.degree.data) db = PostgresDb() check = db.sqlalchemy_session.query(Teacher).filter( Teacher.name == teacher_obj.name).all() if check: form.name.errors = ["Entity already exists"] return render_template('teacher_form.html', form=form, form_name="New teacher", action="new_teacher") db.sqlalchemy_session.add(teacher_obj) db.sqlalchemy_session.commit() return redirect(url_for('index_teacher')) return render_template('teacher_form.html', form=form, form_name="New teacher", action="new_teacher")
def edit_person(): form = TeacherForm() if request.method == 'GET': teacher_login = request.args.get('teacher_login') teacher = db.session.query(ormTeacher).filter(ormTeacher.username == teacher_login).one() # fill form and send to user form.username.data = teacher.username form.password.data = teacher.password form.name.data = teacher.name form.surname.data = teacher.surname form.email.data = teacher.email form.bithday.data = teacher.birthday form.subject.data = teacher.subject form.hobby.data = teacher.hobby # form.photo.data = teacher.photo form.position.data = teacher.position form.proglanguage.data = teacher.proglanguage form.specialization.data = teacher.specialization form.title.data = teacher.title form.works.data = teacher.works return render_template('teacher_form.html', form=form, form_name="Edit teacher", action="edit_teacher") else: if not form.validate(): return render_template('teacher_form.html', form=form, form_name="Edit teacher", action="edit_teacher") else: # find user teacher = db.session.query(ormTeacher).filter(ormTeacher.username == form.username.data).one() # update fields from form data teacher.username = form.username.data teacher.password = form.password.data teacher.name = form.name.data teacher.surname = form.surname.data teacher.email = form.email.data teacher.birthday = form.bithday.data teacher.subject = form.subject.data teacher.hobby = form.hobby.data # teacher.photo = form.photo.data teacher.position = form.position.data teacher.proglanguage = form.proglanguage.data teacher.specialization = form.specialization.data teacher.title = form.title.data teacher.works = form.works.data db.session.commit() return redirect(url_for('teacher'))
def new_teacher(): form = TeacherForm() if request.method == 'POST': if not form.validate(): return render_template('teacher_form.html', form=form, form_name="New teacher", action="new_teacher") else: teacher_obj = Teacher( name=form.name.data, degree=form.degree.data ) db = PostgresDb() db.sqlalchemy_session.add(teacher_obj) db.sqlalchemy_session.commit() return redirect(url_for('index_teacher')) return render_template('teacher_form.html', form=form, form_name="New teacher", action="new_teacher")
def edit_teacher(): if login.isLogged: if login.isAdmin: form = TeacherForm() if request.method == 'GET': name = request.args.get('name') db = PostgresDb() teacher_obj = db.sqlalchemy_session.query(Teacher).filter( Teacher.name == name).one() # fill form and send to user form.name.data = teacher_obj.name form.degree.data = teacher_obj.degree form.old_name.data = teacher_obj.name return render_template('teacher_form.html', form=form, form_name="Edit teacher", action="edit_teacher") else: if not form.validate(): return render_template('teacher_form.html', form=form, form_name="Edit teacher", action="edit_teacher") else: db = PostgresDb() # find professor teacher_obj = db.sqlalchemy_session.query(Teacher).filter( Teacher.name == form.old_name.data).one() # update fields from form data teacher_obj.name = form.name.data teacher_obj.degree = form.degree.data db.sqlalchemy_session.commit() return redirect(url_for('index_teacher'))