Пример #1
0
def edit_user():

    form = UserForm()


    if request.method == 'GET':

        email =request.args.get('email')
        db = OracleDb()
        user = db.sqlalchemy_session.query(ormUser).filter(ormUser.email == email).one()


        form.email.data = user.email
        form.full_name.data = user.full_name
        form.id.data = user.id

        return render_template('user_form.html', form=form, form_name="Edit user", action="edit_user")


    else:

        if form.valemailate() == False:
            return render_template('user_form.html', form=form, form_name="Edit user", action="edit_user")
        else:
            db = OracleDb()
            # find user
            user = db.sqlalchemy_session.query(ormUser).filter(ormUser.email == form.email.data).one()

            # update fields from form data
            user.id = form.id.data
            user.full_name = form.full_name.data

            db.sqlalchemy_session.commit()

            return redirect(url_for('user'))
Пример #2
0
def new_user():

    form = UserForm()

    if request.method == 'POST':
        if form.valemailate() == False:
            return render_template('user_form.html',
                                   form=form,
                                   form_name="New user",
                                   action="new_user")
        else:
            new_user = ormUser(
                id=form.id.data,
                full_name=form.full_name.data,
            )
            db = OracleDb()
            db.sqlalchemy_session.add(new_user)
            db.sqlalchemy_session.commit()

            return redirect(url_for('user'))

    return render_template('user_form.html',
                           form=form,
                           form_name="New user",
                           action="new_user")