def adopt_puppies(puppy_id, adopter_list): adopted_puppy = session.query(Puppy).filter(Puppy.id == puppy_id).one() adopted_puppy.shelter_id = None session.add(adopted_puppy) for adopter in adopter_list: new_adoption = AdoptorsPuppies(adoptor_id=adopter, puppy_id=adopted_puppy.id) session.add(new_adoption) session.commit() return None
def setUp(self): db.create_all() db.session.add(Adoptors(name='Testname',email='*****@*****.**')) db.session.add(Adoptors(name='Billtest',email='*****@*****.**')) db.session.add(Shelter(name="Testshelter", address="123 Fake st.", city="Fake", state="Florida", zipCode="12345", website="http://test.com", maximum_capacity=10, current_capacity=5)) db.session.add(Puppy(name="Testpup", shelter_id=1, gender="male", dateOfBirth=datetime.datetime.now(),picture="http://testpup.com",weight=1, show=True)) db.session.add(Profile(puppy_id=1, breed="Testbreed",description="This is a test description", specialNeeds="Testblind")) db.session.add(Puppy(name="Billpup", shelter_id=1, gender="male", dateOfBirth=datetime.datetime.now(),picture="http://billpup.com",weight=2, show=True)) db.session.add(Profile(puppy_id=2, breed="Testbreed",description="This is a test description1", specialNeeds="Testdeaf")) db.session.add(AdoptorsPuppies(adoptor_id=1, puppy_id=1)) db.session.commit()
def adoption_success(shelter_id, shelter_name, puppy_id, adoptor_id): SHELTERS = Shelter.query.all() puppy = Puppy.query.filter_by(id=puppy_id).one() adoptor = Adoptors.query.filter_by(id=adoptor_id).one() if request.method == 'POST': adoption = AdoptorsPuppies(puppy_id=request.form['puppyname'], adoptor_id=request.form['adoptorname']) puppy.show = False db.session.add(adoption) db.session.add(puppy) db.session.commit() counting_shows() flash('<strong>Successful</strong> adoption', 'success') return redirect(url_for('list_adoptions')) return render_template('adoption_success.html', puppy=puppy, adoptor=adoptor, SHELTERS=SHELTERS)
def adoption_success(shelter_id, shelter_name, puppy_id, adoptor_id): SHELTERS = Shelter.query.all() puppy = Puppy.query.filter_by(id=puppy_id).one() adoptor = Adoptors.query.filter_by(id=adoptor_id).one() if request.method == 'POST': adoption = AdoptorsPuppies(puppy_id=request.form['puppyname'], adoptor_id=request.form['adoptorname']) puppy.show = False db.session.add(adoption) db.session.add(puppy) db.session.commit() counting_shows() send_email(adoptor.name + " just adopted " + puppy.name, "*****@*****.**", ["*****@*****.**"], render_template('email.txt', puppy=puppy, adoptor=adoptor), render_template('email.html', puppy=puppy, adoptor=adoptor)) flash('<strong>Successful</strong> adoption', 'success') return redirect(url_for('list_adoptions')) return render_template('adoption_success.html', puppy=puppy, adoptor=adoptor, SHELTERS=SHELTERS)
db.session.add(new_puppy) db.session.commit() for i, x in enumerate(female_names): new_puppy = Puppy(name=x, gender="female", dateOfBirth=CreateRandomAge(), picture=random.choice(puppy_images), show=True, shelter_id=randint(1, 5), weight=CreateRandomWeight()) db.session.add(new_puppy) db.session.commit() adoption = AdoptorsPuppies(adoptor_id=1, puppy_id=1, adopt_date=datetime.datetime.now()) db.session.add(adoption) db.session.commit() ####################################################################################### ############ Helpful queries ######################################################## ####################################################################################### # Query all puppies in alphabetical order. def get_puppies_by_name(): return db.session.query(Puppy).order_by(Puppy.name).all() # Query all puppies less than 6 months old and order by birthdate with youngest first. def get_baby_puppies():