예제 #1
0
def new_puppy(shelter_id):
    """page to create a new menu item."""
    form = PuppyForm(request.form)
    shelter = session.query(Shelter).filter_by(id = shelter_id).first()
    pdb.set_trace()
    if request.method == "POST" and form.validate():
        if (shelter.maximum_capacity - shelter.current_occupancy) <= 0:
            flash( """
                '{shelter_name}' is full, and the puppy
                '{new_name}' couldn't be added, sorry :(
                """.format(shelter_name=shelter.name, new_name=new_name))
            return redirect(url_for("show_puppies", shelter_id=shelter.id))
        else:
            new_puppy = Puppy()
            form.populate_obj(new_puppy)
            session.add(new_puppy)
            session.commit()
            flash( "new puppy '" + new_puppy.name + "' added!")
            return redirect(url_for("show_puppies", shelter_id=shelter.id))
    else:
        output = render_template('page_head.html', title = "Add a New Puppy! :D", form = 0)
        output += render_template( 'new_puppy.html',
                                   shelter = shelter,
                                   form = form )
        return output
예제 #2
0
def adopt_puppy(adopter_id):
    """page to adopt puppies, accessed from the Adopter directory."""

    if request.method == "POST":
        adopt_this_puppy_id = request.form["adopt_this_puppy_id"]
        adopt_this_puppy_name = session.query(Puppy).\
                                filter_by(id = adopt_this_puppy_id).first().name
        result = session.execute("""
            UPDATE puppy
            SET adopter_id = :adopter_id,
                shelter_id = NULL
            WHERE id = :adopt_this_puppy_id
        """,
        { "adopter_id": adopter_id,
          "adopt_this_puppy_id": adopt_this_puppy_id }
        )
        session.commit()
        flash("Puppy '" + adopt_this_puppy_name + "' adopted! Congrats!")
        return redirect(url_for("adopt_puppy", adopter_id = adopter_id))

    if request.method == "GET":
        output = render_template('page_head.html', title = "Adopt a Puppy!!!", form = 0)
        adopter = session.query(Adopter).filter_by(id = adopter_id).first()
        puppies = session.execute("""
                SELECT *
                FROM puppy
                WHERE adopter_id ISNULL
            """)
        logging.debug( "puppies length is: ", len(puppies) )
        flash("Please select a puppy to adopt.")
        output += render_template( 'adopt_puppy.html',
                                   adopter=adopter,
                                   puppies=puppies )
        return output
예제 #3
0
def edit_puppy(shelter_id, puppy_id):
    """page to edit a puppy's basic information."""
    if request.method == "POST":
        edited_name = request.form['edited_name']
        old_name = session.query(Puppy).filter_by(id = puppy_id).first().name

        result = session.execute("""
                UPDATE puppy
                SET name=:edited_name
                WHERE id=:edited_puppy_id;
            """,
            {"edited_name": edited_name,
            "edited_puppy_id": puppy_id}
        )
        session.commit()
        flash( "item '" +  old_name + "' edited to '" + edited_name + "'. Jawohl!")
        return redirect(url_for("show_puppies", shelter_id=shelter_id))

    else:
        output = render_template('page_head.html', title = "The Menu Manager", form = 0)
        puppy = session.query(Puppy).filter_by(id = puppy_id).first()
        logging.info( "shelter_id is: ", shelter_id )
        if shelter_id == "n":
            shelter = session.query(Shelter).filter_by(id = puppy.shelter_id).first()
        else:
            shelter = session.query(Shelter).filter_by(id = shelter_id).first()
        output += render_template('edit_puppy.html',
                                  shelter = shelter,
                                  puppy = puppy )
        return output
예제 #4
0
def delete_shelter(shelter_id):
    """page to delete a puppy."""
    shelter = session.query(Shelter).filter_by(id=shelter_id).first()
    form = ShelterForm(request.form, shelter)
    if request.method == "POST":
        session.delete(shelter)
        session.commit()
        flash("Shelter '" + shelter.name + "' deleted. Auf Wiedersehen!")
        return redirect(url_for("show_shelters"))

    else:
        output = render_template("page_head.html", title="Delete a Shelter", form=form)
        output += render_template("delete_shelter.html", form=form)
        return output
예제 #5
0
def edit_shelter(shelter_id):
    """page to edit a shelter's basic information."""
    shelter = session.query(Shelter).filter_by(id=shelter_id).first()
    form = ShelterForm(request.form, shelter)
    if request.method == "POST":
        old_name = shelter.name
        form.populate_obj(shelter)
        session.add(shelter)
        session.commit()
        flash("Shelter '" + old_name + "' renamed to '" + shelter.name + "'. Jawohl!")
        return redirect(url_for("show_shelters"))

    else:
        output = render_template("page_head.html", title="Rename Your Shelter", form=form)
        output += render_template("edit_shelter.html", form=form)
        return output
예제 #6
0
def new_shelter():
    """page to create a new shelter."""
    form = ShelterForm(request.form)
    if request.method == "POST" and form.validate():
        new_shelter = Shelter()
        form.populate_obj(new_shelter)
        session.add(new_shelter)
        session.commit()
        flash("New shelter '" + new_shelter.name + "' added!")
        return redirect(url_for("show_shelters"))

    else:
        output = render_template(
            "page_head.html", title="Add a new shelter to the great state of California!", form=form
        )
        output += render_template("new_shelter.html", form=form)
        return output
예제 #7
0
def delete_adopter(adopter_id):
    """page to delete a puppy."""
    adopter = session.query(Adopter).filter_by(id=adopter_id).first()
    form = AdopterForm( request.form, adopter )
    if request.method == "POST":
        session.delete(adopter)
        session.commit()
        flash( "Adopter '" + adopter.name + "' deleted. Auf Wiedersehen!")
        return redirect(url_for("show_adopters"))

    else:
        output = render_template( 'page_head.html',
                                  title = "Delete an Adopter",
                                  form = form )
        output += render_template( 'delete_adopter.html',
                                   form = form )
        return output
예제 #8
0
def new_adopter():
    """page to create a new adopter."""
    form = AdopterForm(request.form)
    if request.method == "POST":
        new_adopter = Adopter()
        form.populate_obj(new_adopter)
        session.add(new_adopter)
        session.commit()
        flash( "New adopter '" + new_adopter.name + "' added!")
        return redirect(url_for("show_adopters"))

    else:
        output = render_template(
            'page_head.html',
            title = "Add a New Adopter! XD",
            form = form )
        output += render_template('new_adopter.html', form = form )
        return output
예제 #9
0
def edit_adopter(adopter_id):
    """page to edit a adopter's basic information."""
    adopter = session.query(Adopter).filter_by(id=adopter_id).first()
    form = AdopterForm( request.form, adopter )
    if request.method == "POST":
        old_name = adopter.name
        form.populate_obj(adopter)
        session.add(adopter)
        session.commit()
        flash( "Adopter '"+old_name+"' renamed to '"+adopter.name+"'. Jawohl!")
        return redirect(url_for("show_adopters"))

    else:
        output = render_template( 'page_head.html',
                                  title = "Edit an Adopter",
                                  form = form )
        output += render_template( 'edit_adopter.html',
                                   form = form )
        return output
예제 #10
0
def delete_puppy(shelter_id, puppy_id):
    """page to delete a puppy."""
    if request.method == "POST":
        delete_this_puppy = session.query(Puppy).filter_by(id = puppy_id).first()
        session.delete(delete_this_puppy)
        session.commit()
        flash( "item '" + delete_this_puppy.name + "' deleted. Auf Wiedersehen!")
        return redirect(url_for("show_puppies", shelter_id=shelter_id))

    else:
        output = render_template('page_head.html', title = "The Menu Manager", form = 0)
        puppy = session.query(Puppy).filter_by(id = puppy_id).first()
        if shelter_id == "n":
            shelter = session.query(Shelter).filter_by(id = puppy.shelter_id).first()
        else:
            shelter = session.query(Shelter).filter_by(id = shelter_id).first()
        output += render_template( 'delete_puppy.html',
                                   puppy = puppy,
                                   shelter = shelter )
        return output
예제 #11
0
	return str(random.uniform(0.1, 100.0))

for i,x in enumerate(male_names):
	new_puppy = Puppy(
		name = x,
		gender = "male",
		dateOfBirth = CreateRandomAge(),
		shelter_id=randint(1,5),
		weight= CreateRandomWeight()
	)
	new_puppy_profile = Puppy_Profile(
		picture=random.choice(puppy_images)
	)
	session.add(new_puppy)
	session.add(new_puppy_profile)
	session.commit()

for i,x in enumerate(female_names):
	new_puppy = Puppy(
		name = x,
		gender = "female",
		dateOfBirth = CreateRandomAge(),
		shelter_id=randint(1,5),
		weight= CreateRandomWeight()
	)
	new_puppy_profile = Puppy_Profile(
		picture=random.choice(puppy_images)
	)
	session.add(new_puppy)
	session.add(new_puppy_profile)
	session.commit()