Ejemplo n.º 1
0
def owner():

    form = AddOwnerForm()

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

        is_puppy = Puppy.query.filter_by(id=pup_id).first()
        if not is_puppy:
            flash(
                'There is no such id number associated with a puppy. Please choose different one.'
            )
            return redirect(url_for('owner'))
        else:
            owner_check = Owner.query.filter_by(puppy_id=pup_id).first()
            if owner_check:
                flash(
                    f'Sorry, but this puppy is already adopted by {owner_check.name}'
                )
                return redirect(url_for('owner'))

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

        return redirect(url_for('list_puppy'))

    return render_template('owner.html', form=form)
Ejemplo n.º 2
0
def add_owner():
    form = AddOwnerForm()
    if form.validate_on_submit():
        name = form.name.data
        pup_id = form.pup_id.data
        new_owner = Owner(name, pup_id)
        db.session.add(new_owner)
        db.session.commit()
        return redirect(url_for('list_pup'))
Ejemplo n.º 3
0
def add_owner():
    form = AddOwnerForm()
    if form.validate_on_submit():
        puppy = Puppy.query.get(form.puppy_id.data)
        new_owner = Owner(form.name.data, puppy.id)
        db.session.add(new_owner)
        db.session.commit()
        return redirect(url_for('list_pup'))
    return render_template('add_owner.html', form=form)
Ejemplo n.º 4
0
def add_owner():
	form = AddOwnerForm()
	if form.validate_on_submit():
		name = form.name.data
		pup_id = form.pup_id.data
		new_owner = Owner(name, pup_id)
		db.session.add(new_owner)
		db.session.commit()
		return redirect(url_for("list_pup"))
	return render_template("add_owner.html", form = form)
Ejemplo n.º 5
0
def add_owner():
    form = AddOwnerForm()
    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('list'))
    return render_template('add_owner.html', form=form)
Ejemplo n.º 6
0
def add_owner():
    form = AddOwnerForm()
    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('add_owner'))
    return render_template('addOwner.html', form=form)
Ejemplo n.º 7
0
def add_owner():
    form = AddOwnerForm()
    if form.validate_on_submit():
        owner_name = form.owner_name.data
        pup_id = form.puppy_id.data
        if Puppy.query.get(pup_id):
            owner = Owner(owner_name, pup_id)
            db.session.add(owner)
            db.session.commit()
        return redirect(url_for('list_pup'))
    return render_template('add_owner.html', form=form)
Ejemplo n.º 8
0
def add_owner():
    form = AddOwnerForm()

    if form.validate_on_submit():
        name = form.name.data
        id = form.id.data
        owner = Owner(name, id)
        db.session.add(owner)
        db.session.commit()
        return redirect(url_for('list_pup'))
    return render_template('owner.html', form=form)
Ejemplo n.º 9
0
def add_owner():
    form = AddOwnerForm()

    if form.validate_on_submit():
        pupid = form.id.data
        owner = form.owner.data
        newowner = Owner(owner, pupid)
        db.session.add(newowner)
        db.session.commit()
        return redirect(url_for('list_pup'))
    return render_template('owners.html', form=form)
Ejemplo n.º 10
0
def add_owner():
    form = AddOwnerForm()

    if form.validate_on_submit():
        name = form.name.data
        phone = form.phone.data
        email = form.email.data
        dog_id = form.dog_id.data
        new_owner = Owner(name, phone, email, dog_id)
        db.session.add(new_owner)
        db.session.commit()

        return redirect(url_for('list_dog'))
    return render_template('add_owner.html', form=form)
Ejemplo n.º 11
0
def add_owner():

    form = AddOwnerForm()

    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('list_pup'))

    return render_template('add_owner.html', form=form)
Ejemplo n.º 12
0
def add_owner():

    form = AddOwnerForm()

    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('list_kit'))

    return render_template('add_owner.html', form=form)
Ejemplo n.º 13
0
def add_own():
    form = AddOwnerForm()

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

        # Add new Puppy to database
        new_owner = Owner(name, puppy_id)
        db.session.add(new_owner)
        db.session.commit()
        flash(f'The owner {new_owner.name} was added successfully')
        return redirect(url_for('list_pup'))

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

    # instantiate AddOwnerForm class.
    form = AddOwnerForm()

    if form.validate_on_submit():
        id = form.pup_id.data
        # puppy = Puppy.query.get(id)
        name = form.name.data
        new_owner = Owner(name, id)
        db.session.add(new_owner)
        db.session.commit()

        return redirect(url_for('list_puppy'))

    return render_template('add_owner.html', form=form)
Ejemplo n.º 15
0
def add_owner():
    form = AddOwnerForm()

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

        # Add new Owner to database
        new_owner = Owner(name, puppy_id)
        db.session.add(new_owner)
        db.session.commit()

        flash(f"You just added an owner with the name {new_owner.name} !")

        return redirect(url_for('list_pup'))

    return render_template('add_owner.html', form=form)
Ejemplo n.º 16
0
def add_owner():

    form = AddOwnerForm()
    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('list_pup'))
    return render_template('add_owner.html', form=form)
Ejemplo n.º 17
0
def add_owner():
    form = AddOwnerForm()

    if form.validate_on_submit():
        new_owner = Owner(name=form.name.data,
                          puppy_id=form.puppy_id.data,
                          address=form.address.data,
                          city=form.city.data,
                          state=form.state.data,
                          phone=form.phone.data)

        sql = (
            f"Insert into owners (name, puppy_id, address, city, state, phone) "
            f"values ('{form.name.data}', '{form.puppy_id.data}', '{form.address.data}', '{form.city.data}', "
            f"'{form.state.data}', '{form.phone.data}');")
        db.engine.execute(sql)

        return redirect(url_for('list_pup'))
    else:
        return render_template('add_owner.html', form=form)
Ejemplo n.º 18
0
def add_owner():

    form = AddOwnerForm()
    if form.validate_on_submit():

        id_puppy = form.id_puppy.data
        owner = form.owner.data

        if owner != "" and id_puppy != "":
            puppy = Puppy.query.get(id_puppy)
            if puppy != None and puppy.owner == None:
                owner = Owner(owner, id_puppy)

                db.session.add(owner)
                db.session.commit()
                return redirect(url_for('list_pups'))
            else:
                return render_template(
                    "error.html", error="Puppy id you provided is not valid")
        else:
            return render_template(
                "error.html", error="Please enter owner's name and puppy id.")

    return render_template("addOwner.html", form=form)