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 edit_student(): form = StudentForm() if request.method == 'GET': name, group = request.args.get('name'), int(request.args.get('group')) db = PostgresDb() student = db.sqlalchemy_session.query(Student).filter(Student.name == name, Student.sgroup == group).one() # fill form and send to student form.name.data = student.name form.group.data = student.sgroup form.old_name.data = student.name form.old_group.data = student.sgroup return render_template('student_form.html', form=form, form_name="Edit student", action="edit_student") else: if not form.validate(): return render_template('student_form.html', form=form, form_name="Edit student", action="edit_student") else: db = PostgresDb() # find student student = db.sqlalchemy_session.query(Student).filter(Student.name == form.old_name.data, Student.sgroup == form.old_group.data).one() # update fields from form data student.name = form.name.data student.sgroup = form.group.data db.sqlalchemy_session.commit() return redirect(url_for('index_student'))
def edit_company(): form = CompaniesForm() if request.method == 'GET': company = request.args.get('name') db = PostgresDb() companyobj = db.sqlalchemy_session.query(Company).filter( Company.Company == company).one() form.Company.data = companyobj.Company form.old_name.data = companyobj.Company return render_template('companies_form.html', form=form, form_name="Edit company", action="new_company") else: if not form.validate(): return render_template('companies_form.html', form=form, form_name="Edit company", action="edit_company") else: db = PostgresDb() companyobj = db.sqlalchemy_session.query(Company).filter( Company.Company == form.old_name.data).one() companyobj.Company = form.Company.data db.sqlalchemy_session.commit() return redirect(url_for('index_company'))
def edit_group(): form = GroupForm() if request.method == 'GET': group_id = request.args.get('group_id') db = PostgresDb() group = db.sqlalchemy_session.query(Group).filter(Group.group_id == group_id).one() # fill form and send to student form.group_id.data = group.group_id form.group_name.data = group.group_name form.group_faculty.data = group.group_faculty return render_template('group_form.html', form=form, form_name="Edit group", action="edit_group") else: if not form.validate(): return render_template('group_form.html', form=form, form_name="Edit group", action="edit_group") else: db = PostgresDb() # find student group = db.sqlalchemy_session.query(Group).filter(Group.group_id == form.group_id.data).one() # update fields from form data group.group_id = form.group_id.data group.group_faculty = form.group_faculty.data group.group_name = form.group_name.data db.sqlalchemy_session.commit() return redirect(url_for('index_group'))
def edit_type(): db = PostgresDb() form = TypeForm() if request.method == 'GET': typeid = request.args.get('name') db = PostgresDb() typeobj = db.sqlalchemy_session.query(Type).filter(Type.id == typeid ).one() form.typename.data = typeobj.typename form.dishname_fk.data = typeobj.dishname_fk form.old_name.data = typeobj.dishname_fk form.old_type.data = typeobj.typename return render_template('type_form.html', form=form, typeid=typeid, form_name="Edit type", action="edit_type") else: if not form.validate(): return render_template('type_form.html', form=form, form_name="Edit type", action="edit_type") else: allobjects = db.sqlalchemy_session.query(Type).all() for el in allobjects: if (el.typename == form.old_type.data and el.dishname_fk == form.old_name.data): typeobj = el typeobj.typename = form.typename.data db.sqlalchemy_session.commit() return redirect(url_for('index_type'))
def edit_discipline(): if login.isLogged: if login.isAdmin: form = DisciplineForm() if request.method == 'GET': name = request.args.get('name') db = PostgresDb() # -------------------------------------------------------------------- filter for "and" google discipline = db.sqlalchemy_session.query(Discipline).filter( Discipline.name == name).one() a = db.sqlalchemy_session.query(Teacher).filter( Teacher.name == discipline.teacher_name).all() if not a: return render_template('discipline_form.html', form=form, form_name="Edit discipline", action="edit_discipline") # fill form and send to discipline form.teacher_name.data = discipline.teacher_name form.name.data = discipline.name form.old_name.data = discipline.name return render_template('discipline_form.html', form=form, form_name="Edit discipline", action="edit_discipline") else: if not form.validate(): return render_template('discipline_form.html', form=form, form_name="Edit discipline", action="edit_discipline") else: db = PostgresDb() # find discipline discipline = db.sqlalchemy_session.query( Discipline).filter( Discipline.name == form.old_name.data).one() a = db.sqlalchemy_session.query(Teacher).filter( Teacher.name == form.teacher_name.data).all() if not a: form.teacher_name.errors = ["No teacher found"] return render_template('discipline_form.html', form=form, form_name="Edit discipline", action="edit_discipline") # update fields from form data discipline.name = form.name.data discipline.teacher_name = form.teacher_name.data db.sqlalchemy_session.commit() return redirect(url_for('index_discipline'))
def signup(): db = PostgresDb() allCompanies = db.sqlalchemy_session.query(Company) allDepartments = db.sqlalchemy_session.query(Department) error = "whhat" error_username = '******' \ ' TRY ANOTHER USERNAME' error_company = 'THERE IS NO SUCH A COMPANY' \ ' TRY ANOTHER COMPANY' error_department = 'THERE IS NO SUCH A DEPARTMENT' \ ' TRY ANOTHER DEPARTMENT' current_user = session.get('username') form = UserForm() if request.method == 'POST': if not form.validate_on_submit(): return render_template('signup.html', form=form) else: new_user = User(Username=form.Username.data, Password=form.Password.data, Company=form.Company.data, Department=form.Department.data) db = PostgresDb() user_check = db.sqlalchemy_session.query(User).filter( User.Username == form.Username.data).all() company_check = db.sqlalchemy_session.query(Company).filter( Company.Company == form.Company.data).all() department_check = db.sqlalchemy_session.query(Department).filter( Department.Department == form.Department.data).all() if (user_check): return render_template('signup.html', form=form, error=error_username) if not (company_check): return render_template('signup.html', form=form, error=error_company) if not (department_check): return render_template('signup.html', form=form, error=error_department) db.sqlalchemy_session.add(new_user) db.sqlalchemy_session.commit() allUsers = db.sqlalchemy_session.query(User).all() session['username'] = new_user.Username current_user = session.get('username') for user in allUsers: if (user.Username == current_user): user_obj = user return render_template('index.html', current_user=current_user, user_obj=user_obj, allCompanies=allCompanies, allDepartments=allDepartments) return render_template('signup.html', form=form, allCompanies=allCompanies, allDepartments=allDepartments)
def edit_message(): form = MessagesForm() db = PostgresDb() if request.method == 'GET': message_id = request.args.get('name') message = db.sqlalchemy_session.query(Message).filter( Message.MessageID == message_id).one() a = db.sqlalchemy_session.query(Message).filter( Message.MessageID == message.MessageID).all() if not a: return render_template('message_form.html', form=form, form_name="Edit message", action="edit_message") print(message.MessageSender) print(message.MessageContent) form.MessageSender.data = message.MessageSender form.MessageContent.data = message.MessageContent form.old_name.data = message.MessageID return render_template('message_form.html', form=form, form_name="Edit message", action="edit_message") else: if not form.validate(): print('form is not validate qwhy') print() return render_template('message_form.html', form=form, form_name="Edit message", action="edit_message") else: print('IM HEREEE') db = PostgresDb() a = db.sqlalchemy_session.query(Message).filter( Message.MessageID == form.old_name.data).all() if not a: return render_template('message_form.html', form=form, form_name="Edit message", action="edit_message") print('IM HERE TOOOO') message = db.sqlalchemy_session.query(Message).filter( Message.MessageID == form.old_name.data).one() message.MessageContent = form.MessageContent.data db.sqlalchemy_session.commit() return redirect(url_for('index_message'))
def edit_user(): form = UserForm() if request.method == 'GET': name = request.args.get('name') db = PostgresDb() user = db.sqlalchemy_session.query(User).filter( User.Username == name).one() a = db.sqlalchemy_session.query(Company).filter( Company.Company == user.Company).all() if not a: return render_template('user_form.html', form=form, form_name="Edit user", action="edit_user") form.Username.data = user.Username form.Password.data = user.Password form.Company.data = user.Company form.old_name.data = user.Username return render_template('user_form.html', form=form, form_name="Edit user", action="edit_user") else: if not form.validate(): return render_template('user_form.html', form=form, form_name="Edit user", action="edit_user") else: db = PostgresDb() a = db.sqlalchemy_session.query(Company).filter( Company.Company == form.Company.data).all() if not a: return render_template('user_form.html', form=form, form_name="Edit user", action="edit_user") user = db.sqlalchemy_session.query(User).filter( User.Username == form.old_name.data).one() user.Username = form.Username.data user.Password = form.Password.data user.Company = form.Company.data db.sqlalchemy_session.commit() return redirect(url_for('index_user'))
def edit_task(): if login.isLogged: if login.isAdmin: form = TaskFrom() if request.method == 'GET': name = request.args.get('name') db = PostgresDb() task_obj = db.sqlalchemy_session.query(Task).filter( Task.name == name).one() # fill form and send to user form.name.data = task_obj.name form.discipline_name.data = task_obj.discipline_name form.value.data = task_obj.value form.deadline.data = task_obj.deadline form.old_name.data = task_obj.name return render_template('task_form.html', form=form, form_name="Edit task", action="edit_task") else: if not form.validate(): return render_template('task_form.html', form=form, form_name="Edit task", action="edit_task") else: db = PostgresDb() # find professor task_obj = db.sqlalchemy_session.query(Task).filter( Task.name == form.old_name.data).one() d = db.sqlalchemy_session.query(Discipline).filter( Discipline.name == form.discipline_name.data).all() if not d: form.discipline_name.errors = ["No discipline found"] return render_template('task_form.html', form=form, form_name="Edit task", action="edit_task") # update fields from form data task_obj.name = form.name.data task_obj.discipline_name = form.discipline_name.data task_obj.value = form.value.data task_obj.deadline = form.deadline.data db.sqlalchemy_session.commit() return redirect(url_for('index_task'))
def new_univer(): form = UniverForm() if request.method == 'POST': if not form.validate(): return render_template('univer_form.html', form=form, form_name="New univer", action="new_univer") else: subject_obj = Univer(name=form.name.data, addr=form.addr.data, counter=form.counter.data, balamce=form.balance.data) db = PostgresDb() db.sqlalchemy_session.add(univer_obj) db.sqlalchemy_session.commit() return redirect(url_for('index_univer')) return render_template('univer_form.html', form=form, formname="New univer", action="new_univer")
def new_student_task(): if login.isLogged: if login.isAdmin: form = Student_TaskForm() if request.method == 'POST': if not form.validate(): return render_template('student_task_from.html', form=form, form_name="New student_task", action="new_student_task") else: db = PostgresDb() student_task_obj = Student_Task( task_id=form.task_id.data, student_name=form.student_name.data, student_group=form.student_group.data) check = db.sqlalchemy_session.query(Student_Task).filter( Student_Task.task_id == student_task_obj.task_id, Student_Task.student_name == student_task_obj.student_name, Student_Task.student_group == student_task_obj.student_group).all() if check: form.name.errors = ["Entity already exists"] return render_template('student_task_form.html', form=form, form_name="New student_task", action="new_student_task") s = db.sqlalchemy_session.query(Student).filter( Student.name == student_task_obj.student_name, Student.sgroup == student_task_obj.student_group).all() if not s: form.student_name.errors = ["No student found"] return render_template('student_task_form.html', form=form, form_name="New student_task", action="new_student_task") t = db.sqlalchemy_session.query(Task).filter( Task.id == student_task_obj.task_id).all() if not t: form.task_id.errors = ["No tasks found"] return render_template('student_task_form.html', form=form, form_name="New student_task", action="new_student_task") db.sqlalchemy_session.add(student_task_obj) db.sqlalchemy_session.commit() return redirect(url_for('index_student_task')) return render_template('student_task_form.html', form=form, form_name="New student_task", action="new_student_task")
def new_ganre(): form = GanreForm() db = PostgresDb() if request.method == 'POST': if not form.validate(): return render_template('form_for_genre.html', form=form, form_name="New Ganre", action="i") else: genre_id = list(db.sqlalchemy_session.query(func.max( ormGanre.id)))[0][0] ganre_obj = ormGanre( id=genre_id + 1, name=form.genre_name.data, popularity=form.genre_popularity.data, count_of_subscribers=form.genre_count_of_subscribers.data, year=form.genre_year.data) db.sqlalchemy_session.add(ganre_obj) db.sqlalchemy_session.commit() return redirect(url_for('show_values')) return render_template('form_for_genre.html', form=form, form_name="New Ganre", action='i')
def new_message(): db = PostgresDb() form = MessagesForm() current_user = session.get('username') allUsers = db.sqlalchemy_session.query(User).all() if request.method == 'POST': if not form.validate(): return render_template('message_form.html', current_user=current_user, form=form, form_name="New message", action="new_message") else: message_obj = Message(MessageSender=current_user, MessageContent=form.MessageContent.data, MessageDate=date.today()) db.sqlalchemy_session.add(message_obj) db.sqlalchemy_session.commit() for user in allUsers: if (user.Username == current_user): user_obj = user return redirect(url_for('index_message')) return render_template('message_form.html', current_user=current_user, form=form, form_name="New message", action="new_message")
def new_user(): form = UserForm() if request.method == 'POST': if not form.validate(): return render_template('user_form.html', form=form, form_name="New user", action="new_user") else: user_obj = User(Username=form.Username.data, Password=form.Password.data, Company=form.Company.data) db = PostgresDb() a = db.sqlalchemy_session.query(Company).filter( Company.Company == form.Company.data).all() b = db.sqlalchemy_session.query(User).filter( User.Username == form.Username.data).all() if not a: return redirect(url_for('index_user')) if b: return redirect(url_for('index_user')) db.sqlalchemy_session.add(user_obj) db.sqlalchemy_session.commit() return render_template('user_form.html', form=form, form_name="New user", action="new_user")
def dashboard(): db = PostgresDb() group_form = GroupSearchForm() group_form.init() pie_labels = [] data = {"bar": []} for query, label in zip(*group_form.search(method=request.method)): if not query: continue groups, counts = zip(*query) pie = go.Pie(labels=[f'group = {group}' for group in groups], values=counts) data[label] = [pie] pie_labels.append(label) points = db.sqlalchemy_session.query( Subject.subj_name, Subject.subj_hours).distinct( Subject.subj_name, Subject.subj_hours).filter(Subject.subj_name != '').all() semester, final = zip(*points) bar = go.Scatter(x=semester, y=final, mode='markers') data["bar"].append(bar) json_data = json.dumps(data, cls=plotly.utils.PlotlyJSONEncoder) return render_template('dashboard.html', json=json_data, pie_labels=pie_labels, group_form=group_form)
def search(self, method): db = PostgresDb() result, labels = [], [] query = db.sqlalchemy_session.query(Group.group_faculty).distinct( Group.group_faculty) if method == 'POST': if self.faculty.data and self.faculty.data != "None": query = query.filter(Group.group_faculty == self.faculty.data) student_faculty_set = query.all() for faculty in student_faculty_set: query = db.sqlalchemy_session.query( Group.group_name, func.count(Group.group_name)).group_by( Group.group_name).filter(Group.group_faculty == faculty) if method == "POST": if self.group.data and self.group.data != "None": query = query.filter(Group.group_name == self.group.data) if self.name.data and self.name.data != "None": query = query.filter(Group.group_faculty == self.name.data) result.append(query.all()) labels.append(f'faculty {faculty}') return result, labels
def new_message(): db = PostgresDb() form = MessagesForm() if request.method == 'POST': if not form.validate(): return render_template('message_form.html', form=form, form_name="New message", action="new_message") else: message_obj = Message(MessageSender=form.MessageSender.data, MessageContent=form.MessageContent.data, MessageDate=date.today()) print(message_obj) a = db.sqlalchemy_session.query(User).filter( User.Username == form.MessageSender.data).all() # b = db.sqlalchemy_session.query(User).filter(User.Username == form.Username.data).all() if not a: return redirect(url_for('new_message')) # if b: # return redirect(url_for('index_user')) db.sqlalchemy_session.add(message_obj) db.sqlalchemy_session.commit() return redirect(url_for('index_message')) return render_template('message_form.html', form=form, form_name="New message", action="new_message")
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 new_receipt(): form = ReceiptForm() if request.method == 'POST': if not form.validate(): return render_template('receipt_form.html', form=form, form_name="New receipt", action="new_receipt") else: receipt_obj = Receipt(dishname_fk=form.dishname_fk.data, receipt_content=form.receipt_content.data) db = PostgresDb() a = db.sqlalchemy_session.query(Dish).filter( Dish.dishname == form.dishname_fk.data).all() if not a: return render_template('receipt_form.html', form=form, form_name="New receipt", action="new_receipt") db.sqlalchemy_session.add(receipt_obj) db.sqlalchemy_session.commit() return redirect(url_for('index_receipt')) return render_template('receipt_form.html', form=form, form_name="New receipt", action="new_receipt")
def new_discipline(): form = DisciplineForm() if request.method == 'POST': if not form.validate(): return render_template('discipline_form.html', form=form, form_name="New discipline", action="new_discipline") else: discipline_obj = Discipline(name=form.name.data, teacher_name=form.teacher_name.data) db = PostgresDb() a = db.sqlalchemy_session.query(Teacher).filter( Teacher.name == form.teacher_name.data).all() if not a: return render_template('discipline_form.html', form=form, form_name="New discipline", action="new_discipline") db.sqlalchemy_session.add(discipline_obj) db.sqlalchemy_session.commit() return redirect(url_for('index_discipline')) return render_template('discipline_form.html', form=form, form_name="New discipline", action="new_discipline")
def edit_work(): form = Work1Form() if request.method == 'GET': subj_faculty_fk, subj_name_fk = request.args.get('subj_faculty_fk'), \ request.args.get('subj_name_fk') db = PostgresDb() # -------------------------------------------------------------------- filter for "and" google work = db.sqlalchemy_session.query(Work1).filter( Work1.subj_faculty_fk == subj_faculty_fk, Work1.subj_name_fk == subj_name_fk).one() # fill form and send to discipline form.name.data = work.name form.company.data = work.company form.salary.data = work.salary form.open_date.data = work.open_date form.subj_name_fk.data = work.subj_name_fk form.subj_faculty_fk.data = work.subj_faculty_fk form.old_subj_faculty_fk.data = work.subj_faculty_fk form.old_subj_name_fk.data = work.subj_name_fk return render_template('work_form.html', form=form, form_name="Edit work", action="edit_work") else: if not form.validate(): return render_template('work_form.html', form=form, form_name="Edit work", action="edit_work") else: db = PostgresDb() # find discipline work = db.sqlalchemy_session.query(Work1).filter( Work1.subj_faculty_fk == form.old_subj_faculty_fk.data, Work1.subj_name_fk == form.old_subj_name_fk.data).one() # update fields from form data work.name = form.name.data work.company = form.company.data work.salary = form.salary.data work.open_date = form.open_date.data work.subj_name_fk = form.subj_name_fk.data work.subj_faculty_fk = form.subj_faculty_fk.data db.sqlalchemy_session.commit() return redirect(url_for('index_univer'))
def update(): form = SkillForm() if request.method == 'GET': student_name = request.args.get('student_name') student_group = request.args.get('student_group') name = request.args.get('name') db = PostgresDb() skill_obj = db.sqlalchemy_session.query(Skill).filter(Skill.student_name == student_name, Skill.student_group == student_group, Skill.name == name ).one() # fill form and send to user form.student_name.data=skill_obj.student_name form.student_group.data=skill_obj.student_group form.vacancy.data = skill_obj.vacancy form.type.data=skill_obj.type form.creation_date.data = skill_obj.creation_date form.name.data = skill_obj.name form.old_name.data = skill_obj.name return render_template('skill_form.html', form=form, form_name="Edit skill", action="update") else: if not form.validate(): return render_template('skill_form.html', form=form, form_name="Edit skill", action="update") else: db = PostgresDb() # find professor skill_obj = db.sqlalchemy_session.query(Skill).filter(Skill.student_name == form.student_name.data, Skill.student_group == form.student_group.data, Skill.name == form.old_name.data ).one() # update fields from form data skill_obj.type = form.type.data skill_obj.vacancy = form.vacancy.data skill_obj.creation_date = form.creation_date.data skill_obj.name = form.name.data db.sqlalchemy_session.commit() return redirect(url_for('show'))
def root(): if login.isLogged: if login.isAdmin: return render_template('index.html') else: db = PostgresDb() user = db.sqlalchemy_session.query(Users).filter( Users.name == login.name, Users.password == login.password).all() tasks = db.sqlalchemy_session.query(Student_Task).filter( Student_Task.student_name == user[0].name, Student_Task.student_group == user[0].sgroup).all() return render_template('Student_index.html', tasks=tasks) else: form = UserForm() if request.method == 'GET': return render_template('login_form.html', form=form, form_name="Login", action="") else: if not form.validate(): return render_template('login_form.html', form=form, form_name="Login", action="") db = PostgresDb() # find professor user = db.sqlalchemy_session.query(Users).filter( Users.name == form.name.data, Users.password == form.password.data).all() if user: login.Login(name=user[0].name, password=user[0].password) tasks = db.sqlalchemy_session.query(Student_Task).filter( Student_Task.student_name == user[0].name, Student_Task.student_group == user[0].sgroup).all() return render_template('Student_index.html', tasks=tasks) elif form.name.data == 'admin' and form.password.data == 'admin': login.Login(name='admin', password='******', isAdmin=True) return render_template('index.html') else: return render_template('login_form.html', form=form, form_name="Login", action="")
def edit_univer(): form = UniverForm() if request.method == 'GET': addr, name = request.args.get('addr'), \ request.args.get('name') db = PostgresDb() # -------------------------------------------------------------------- filter for "and" google univer = db.sqlalchemy_session.query(Univer).filter( Univer.addr == addr, Univer.name == name).one() # fill form and send to discipline form.addr.data = univer.addr form.name.data = univer.name form.counter.data = univer.counter form.balance.data = univer.balance return render_template('univer_form.html', form=form, form_name="Edit univer", action="edit_univer") else: if not form.validate(): return render_template('univer_form.html', form=form, form_name="Edit univer", action="edit_univer") else: db = PostgresDb() # find discipline univer = db.sqlalchemy_session.query(Univer).filter( Univer.addr == form.addr.data, Univer.name == form.name.data).one() # update fields from form data univer.addr = form.addr.data univer.name = form.name.data univer.counter = form.counter.data univer.balance = form.balance.data db.sqlalchemy_session.commit() return redirect(url_for('index_univer'))
def edit_student(): form = StudentForm() db = PostgresDb() if request.method == 'GET': id = request.args.get('id') student_obj = db.sqlalchemy_session.query(student).filter( student.id == id).one() # fill form and send to user form.id.data = student_obj.id form.faculty.data = student_obj.faculty form.group.data = student_obj.group form.name.data = student_obj.name form.surname.data = student_obj.surname form.username.data = student_obj.username return render_template('new_student.html', form=form, form_name="Редагувати інформацію про студента", action="edit_student") else: if not form.validate(): return render_template( 'new_student.html', form=form, form_name="Редагувати інформацію про студента", action="edit_student") else: db = PostgresDb() # find professor student_obj = db.sqlalchemy_session.query(student).filter( student.id == form.id.data).one() # update fields from form data student_obj.id = form.id.data student_obj.faculty = form.faculty.data student_obj.group = form.group.data student_obj.name = form.name.data student_obj.surname = form.surname.data student_obj.username = form.username.data db.sqlalchemy_session.commit() return redirect(url_for('show_tables'))
def edit_subject(): form = SubjectForm() if request.method == 'GET': subject_faculty, subject_name = request.args.get('subj_faculty'), \ request.args.get('subj_name') db = PostgresDb() # -------------------------------------------------------------------- filter for "and" google subject = db.sqlalchemy_session.query(Subject).filter( Subject.subj_faculty == subject_faculty, Subject.subj_name == subject_name).one() # fill form and send to discipline form.subject_faculty.data = subject.subj_faculty form.subject_name.data = subject.subj_name form.subject_hours.data = subject.subj_hours return render_template('subject_form.html', form=form, form_name="Edit subject", action="edit_subject") else: if not form.validate(): return render_template('subject_form.html', form=form, form_name="Edit subject", action="edit_subject") else: db = PostgresDb() # find discipline subject = db.sqlalchemy_session.query(Subject).filter( Subject.subj_faculty == form.subject_faculty.data, Subject.subj_name == form.subject_name.data).one() # update fields from form data subject.subj_faculty = form.subject_faculty.data subject.subj_name = form.subject_name.data subject.subj_hours = form.subject_hours.data db.sqlalchemy_session.commit() return redirect(url_for('index_subject'))
def index_discipline(): if login.isLogged: if login.isAdmin: db = PostgresDb() discipline = db.sqlalchemy_session.query(Discipline).all() return render_template('discipline.html', disciplines=discipline)
def index_student(): if login.isLogged: if login.isAdmin: db = PostgresDb() result = db.sqlalchemy_session.query(Student).all() return render_template('student.html', students=result)
def index_task(): if login.isLogged: if login.isAdmin: db = PostgresDb() result = db.sqlalchemy_session.query(Task).all() return render_template('task.html', tasks=result)