def new_student():
    form = StudentForm()

    if request.method == 'POST':
        if not form.validate():
            return render_template('studentn_form.html', form=form, form_name="New student", action="new_student")
        else:
            new_student = 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,
                group =form.group.data,
                hobby = form.hobby.data,
              # photo = form.photo.data,
                grades = form.grades.data,
                proglanguage = form.proglanguage.data,
                specialization = form.specialization.data,
                subject = form.subject.data)

            role = db.session.query(ormRole).filter(ormRole.name == "User").one()

            new_student.roles.append(role)

            db.session.add(new_student)
            db.session.commit()

            return redirect(url_for('student'))

    return render_template('student_form.html', form=form, form_name="New student", action="new_student")
Exemple #2
0
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_person():
    form = StudentForm()

    if request.method == 'GET':

        student_login = request.args.get('student_login')
        student = db.session.query(ormStudent).filter(ormStudent.username == student_login).one()

        # fill form and send to user
        form.username.data = student.username
        form.password.data = student.password
        form.name.data = student.name
        form.surname.data = student.surname
        form.email.data = student.email
        form.bithday.data = student.bithday
        form.group.data = student.group
        form.hobby.data = student.hobby
        # form.photo.data = student.photo
        form.grades.data = student.grades
        form.proglanguage.data = student.proglanguage
        form.specialization.data = student.specialization
        form.subject.data = student.subject

        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:
            # find user
            student = db.session.query(ormStudent).filter(ormStudent.username == form.username.data).one()

            # update fields from form data
            student.username = form.username.data
            student.password = form.password.data
            student.name = form.name.data
            student.surname = form.surname.data
            student.email = form.email.data
            student.birthday = form.bithday.data
            student.group = form.group.data
            student.hobby = form.hobby.data
            # student.photo = form.photo.data
            student.grades = form.grades.data
            student.proglanguage = form.proglanguage.data
            student.specialization = form.specialization.data
            student.subject = form.subject.data

            db.session.commit()

            return redirect(url_for('student'))
Exemple #4
0
def new_student():
    form = StudentForm()

    if request.method == 'POST':
        if not form.validate():
            return render_template('student_form.html', form=form, form_name="New student", action="new_student")
        else:
            student_obj = Student(
                name=form.name.data,
                sgroup=form.group.data
            )

            db = PostgresDb()
            db.sqlalchemy_session.add(student_obj)
            db.sqlalchemy_session.commit()

            return redirect(url_for('index_student'))

    return render_template('student_form.html', form=form, form_name="New student", action="new_student")
Exemple #5
0
def new_student():
    if login.isLogged:
        if login.isAdmin:
            form = StudentForm()

            if request.method == 'POST':
                if not form.validate():
                    return render_template('student_form.html',
                                           form=form,
                                           form_name="New student",
                                           action="new_student")
                else:
                    student_obj = Student(name=form.name.data,
                                          sgroup=form.group.data)

                    db = PostgresDb()

                    check = db.sqlalchemy_session.query(Student).filter(
                        Student.name == student_obj.name,
                        Student.sgroup == student_obj.sgroup).all()
                    if check:
                        form.name.errors = ["Entity already exists"]
                        return render_template('student_form.html',
                                               form=form,
                                               form_name="New student",
                                               action="new_student")

                    db.sqlalchemy_session.add(student_obj)
                    db.sqlalchemy_session.commit()

                    return redirect(url_for('index_student'))

            return render_template('student_form.html',
                                   form=form,
                                   form_name="New student",
                                   action="new_student")