Beispiel #1
0
def edit_user(user_id):
    user = Adopter.query.filter_by(id=user_id).one()
    form = UserForm(obj=user)
    if form.validate_on_submit():
        user.name = form.name.data
        user.gender = form.gender.data
        user.address = form.address['address'].data
        user.city = form.address['city'].data
        user.state = form.address['state'].data
        user.zipCode = form.address['zip_code'].data
        user.dateOfBirth = form.date_of_birth.data
        user.email = form.email.data
        db.session.add(user)
        db.session.commit()
        if app.debug:
            app.logger.debug("User {} edited!".format((user_id, user.name)))
        flash("User {} edited!".format((user_id, user.name)))
        return redirect(url_for('index'))
    else:
        form.date_of_birth.data = user.dateOfBirth
        form.address['address'].data = user.address
        form.address['city'].data = user.city
        form.address['state'].data = user.state
        form.address['zip_code'].data = user.zipCode
        return render_template('edituser.html', form=form, user=user)
def edit_user(user_id):
    user = Adopter.query.filter_by(id=user_id).one()
    form = UserForm(obj=user)
    if form.validate_on_submit():
        user.name = form.name.data
        user.gender = form.gender.data
        user.address = form.address['address'].data
        user.city = form.address['city'].data
        user.state = form.address['state'].data
        user.zipCode = form.address['zip_code'].data
        user.dateOfBirth = form.date_of_birth.data
        user.email = form.email.data
        db.session.add(user)
        db.session.commit()
        if app.debug:
            app.logger.debug("User {} edited!".format(
                (user_id, user.name)))
        flash("User {} edited!".format(
            (user_id, user.name)))
        return redirect(url_for('index'))
    else:
        form.date_of_birth.data = user.dateOfBirth
        form.address['address'].data = user.address
        form.address['city'].data = user.city
        form.address['state'].data = user.state
        form.address['zip_code'].data = user.zipCode
        return render_template('edituser.html', form=form, user=user)
Beispiel #3
0
def new_user():
    form = UserForm(request.form)
    if form.validate_on_submit():
        user = Adopter(name=form.name.data,
                       gender=form.gender.data,
                       address=form.address['address'].data,
                       city=form.address['city'].data,
                       state=form.address['state'].data,
                       zipCode=form.address['zip_code'].data,
                       dateOfBirth=form.date_of_birth.data,
                       email=form.email.data)
        db.session.add(user)
        db.session.commit()
        if app.debug:
            app.logger.debug("User {} edited!".format((user.id, user.name)))
        flash("User {} edited!".format((user.id, user.name)))
        return redirect(url_for('index'))
    else:
        return render_template('newuser.html', form=form)
def new_user():
    form = UserForm(request.form)
    if form.validate_on_submit():
        user = Adopter(name=form.name.data, gender=form.gender.data,
                       address=form.address['address'].data,
                       city=form.address['city'].data,
                       state=form.address['state'].data,
                       zipCode=form.address['zip_code'].data,
                       dateOfBirth=form.date_of_birth.data,
                       email=form.email.data)
        db.session.add(user)
        db.session.commit()
        if app.debug:
            app.logger.debug("User {} edited!".format(
                (user.id, user.name)))
        flash("User {} edited!".format(
            (user.id, user.name)))
        return redirect(url_for('index'))
    else:
        return render_template('newuser.html', form=form)