Example #1
0
def add():

    form = AddForm()

    not_id_mess = ''

    if form.validate_on_submit():
        name = form.name.data
        puppy_id = form.puppy_id.data

        cur_pup = Puppy.query.get(puppy_id)

        if cur_pup:
            flash('You successfully added the owner to the puppy!')

            cur_owner = Owner(name, puppy_id)
            cur_pup.owner = cur_owner

            db.session.add_all([cur_owner, cur_pup])
            db.session.commit()

            return redirect(url_for('puppies.list'))

        else:
            not_id_mess = f'Sorry, but we do not have the puppy with id: {puppy_id} '
            return render_template('add_owner.html',
                                   form=form,
                                   not_id_mess=not_id_mess)

    return render_template('add_owner.html',
                           form=form,
                           not_id_mess=not_id_mess)
Example #2
0
def add_owner():
    form = AddForm()
    if form.validate_on_submit():
        name = form.name.data
        puppy_id = form.puppy_id.data
        owner = Owner(name, puppy_id)
        db.session.add(owner)
        db.session.commit()
        return redirect(url_for('puppies.list_pup'))
    return render_template('addowner.html', form=form)
Example #3
0
def add():
    form = AddForm()
    if form.validate_on_submit():
        name = form.name.data
        pup_id = form.pup_id.data
        # Add new owner to database
        new_owner = Owner(name, pup_id)
        db.session.add(new_owner)
        db.session.commit()
        return redirect(url_for("puppies.list"))
    return render_template("add_owner.html", form=form)
Example #4
0
def add():
    form = AddForm()

    if form.validate_on_submit():
        pupid = form.pupid.data
        owner = form.name.data
        newowner = Owner(owner, pupid)
        db.session.add(newowner)
        db.session.commit()
        return redirect(url_for('puppies.list'))
    return render_template('add_owner.html', form=form)
def add_owner():
    form = AddForm()
    if form.validate_on_submit():
        owner_name = form.owner.data
        cat_id = form.cat_id.data
        cur_owner = Owner(owner_name, cat_id)
        db.session.add(cur_owner)
        db.session.commit()
        return redirect(
            url_for('cats.cat_list'))  # !!! changed name of end_point
    return render_template('add_owner.html', form=form)
Example #6
0
def add():
    form = AddForm()

    if form.validate_on_submit():
        owner = Owner(form.owner_name.data, form.puppy_id.data)
        db.session.add(owner)
        db.session.commit()
        flash(f"Owner {owner.name} has been registered")
        return redirect(url_for('puppies.list'))

    return render_template('add_owner.html', form=form)
Example #7
0
def add():
    form = AddForm()

    if form.validate_on_submit():
        new_owner = Owner(form.name_owner.data, form.id_pup.data)
        db.session.add(new_owner)
        db.session.commit()

        return redirect(url_for('puppies.list'))

    return render_template('add_owner.html', form=form)
Example #8
0
def add_own():
    form = AddOwner()

    if form.validate_on_submit():
        name = form.name.data
        pup_id = form.pup_id.data

        new_own = Owner(name, pup_id)
        db.session.add(new_own)
        db.session.commit()

        flash('Owner Added Successfully!')
        return redirect(url_for('puppies.list_pup'))
    return render_template('addowner.html', form=form)
Example #9
0
def add():

    form = AddForm()

    if form.validate_on_submit():
        name = form.name.data
        puppy_id = form.puppy_id.data
        new_owner = Owner(name=name, puppy_id=puppy_id)
        db.session.add(new_owner)
        db.session.commit()
        flash(f'You just added owner: {new_owner.name}')

        return redirect(url_for('owners.add'))
    return render_template('add_owner.html', form=form)
Example #10
0
def add():
    form = AddForm()
    if form.validate_on_submit():

        name = form.name.data
        puppy_id = form.puppy_id.data
        pup = Puppy.query.get(puppy_id)
        pup_name = pup.name
        owner = Owner(name, puppy_id)
        db.session.add(owner)
        db.session.commit()
        # flash(
        #     f'Thanks for adopting {pup_name.capitalize()}, {owner.name.capitalize()}!')
        return redirect(url_for('puppies.list'))
    return render_template('add_owner.html', form=form)
Example #11
0
def add():

    form = AddForm()

    if form.validate_on_submit():
        name = form.name.data
        kit_id = form.kit_id.data

        new_owner = Owner(name, kit_id)
        db.session.add(new_owner)
        db.session.commit()

        return redirect(url_for('kittens2.list'))

    return render_template('add_owner.html', form = form)
def add():

    form = AddForm()

    if form.validate_on_submit():

        name = form.name.data
        cat_id = form.cat_id.data
        # add new owner to database
        new_owner = Owner(name, cat_id)
        db.session.add(new_owner)
        db.session.commit()

        return redirect(url_for('list_cat'))

    return render_template('add.html', form=form)
def add():

    form = AddForm()

    if form.validate_on_submit():
        name = form.name.data
        pup_id = form.id.data
        #add now owner to database
        new_owner = Owner(name, pup_id)
        db.session.add(new_owner)
        db.session.commit()

        #blueprintname = puppies and #view (function) -> list()
        return redirect(url_for('puppies.list'))

    return render_template('add_owner.html', form=form)
Example #14
0
def add_owner():

    form = AddForm()

    # add new puppy to the db
    if form.validate_on_submit():

        name = form.name.data
        puppy_id = form.puppy_id.data

        new_owner = Owner(name, puppy_id)
        db.session.add(new_owner)
        db.session.commit()

        # puppies.list references the template
        return redirect(url_for('puppies.list_pup'))

    return render_template('add_owner.html', form=form)