Esempio n. 1
0
def newPuppy(shelter_id):
    form = NewPuppyForm(request.form)
    if request.method == 'POST' and form.validate():
        shelter = session.query(Shelter).filter_by(id=shelter_id).one()
        if shelter.current_occupancy >= shelter.maximum_capacity:
            flash('Shelter already at maximum capacity. Please try \
                another one')
            # reload page and display the flash messaage
            return render_template(
                'newpuppy.html',
                form=form, shelter_id=shelter_id
            )
        shelter.current_occupancy += 1
        session.add(shelter)
        puppy = Puppy()
        puppy.name = form.name.data
        puppy.gender = form.gender.data
        puppy.weight = form.weight.data
        puppy.shelter_id = shelter_id
        puppy.dateOfBirth = datetime.strptime(form.dob.data, '%Y-%m-%d').date()
        session.add(puppy)
        session.commit()
        flash('new puppy added', 'warn')
        # Go back to shelter page
        return redirect(url_for('shelterPage', shelter_id=shelter_id))
    else:
        # Show form
        return render_template(
            'newpuppy.html',
            form=form, shelter_id=shelter_id
        )
Esempio n. 2
0
def AddABunchOfFakePuppies():
    engine = create_engine('sqlite:///puppyweb.db')

    Base.metadata.bind = engine

    DBSession = sessionmaker(bind=engine)

    session = DBSession()


    #Add Shelters
    shelter1 = Shelter(name = "San Juan Animal Services", city = "San Juan")
    session.add(shelter1)

    shelter2 = Shelter(name = "San Juan Adoption Center", city="San Juan")
    session.add(shelter2)

    shelter3 = Shelter(name = "Carolina Dog Rescue", city = "Carolina")
    session.add(shelter3)

    shelter4 = Shelter(name = "Humane Society of Luqillo",city = "Luquillo")
    session.add(shelter4)

    shelter5 = Shelter(name = "Bayamon Humane Society" ,city = "Bayamon")
    session.add(shelter5)


    #Add Puppies

    gender = ["male", "female"]

    male_names = ["Bailey", "Max", "Charlie", "Buddy","Rocky","Jake", "Jack", "Toby", "Cody", "Buster",
                  "Duke", "Cooper", "Riley", "Harley", "Bear", "Tucker", "Murphy", "Lucky", "Oliver",
                  "Sam", "Oscar", "Teddy", "Winston", "Sammy", "Rusty", "Shadow", "Gizmo", "Bentley",
                  "Zeus", "Jackson", "Baxter", "Bandit", "Gus", "Samson", "Milo", "Rudy", "Louie", "Hunter",
                  "Casey", "Rocco", "Sparky", "Joey", "Bruno", "Beau", "Dakota", "Maximus", "Romeo", "Boomer", "Luke", "Henry"]

    female_names = ['Bella', 'Lucy', 'Molly', 'Daisy', 'Maggie', 'Sophie', 'Sadie', 'Chloe', 'Bailey', 'Lola',
                    'Zoe', 'Abby', 'Ginger', 'Roxy', 'Gracie', 'Coco', 'Sasha', 'Lily', 'Angel', 'Princess',
                    'Emma', 'Annie', 'Rosie', 'Ruby', 'Lady', 'Missy', 'Lilly', 'Mia', 'Katie', 'Zoey', 'Madison',
                    'Stella', 'Penny', 'Belle', 'Casey', 'Samantha', 'Holly', 'Lexi', 'Lulu', 'Brandy', 'Jasmine',
                    'Shelby', 'Sandy', 'Roxie', 'Pepper', 'Heidi', 'Luna', 'Dixie', 'Honey', 'Dakota']
    names = {"male": male_names, "female":female_names}


    puppy_images = ["images/Puppy1.PNG",
                    "images/Puppy2.PNG",
                    "images/Puppy3.PNG",
                    "images/Puppy4.PNG",
                    "images/Puppy5.PNG",
                    "images/Puppy6.PNG",
                    "images/Puppy7.PNG"]

    breeds = ["Mutt", "Corgi", "Terrier", "Cockerspaniel", "Pommeranian", "Weiner Dog", "Collie"]

    descriptions = ["Well-behaved, friendly", "Nice to people, aggressive towards other dogs", "Very energetic"]

    for pupImage in puppy_images:
        newPup = Puppy()
        newPup.gender = random.choice(gender)
        newPup.name = random.choice(names[newPup.gender])
        newPup.dateOfBirth = CreateRandomAge()
        newPup.breed = random.choice(breeds)
        newPup.description = random.choice(descriptions)
        newPup.shelter_id=randint(1,5)
        newPup.weight= CreateRandomWeight()
        newPup.pictureURL = pupImage
        session.add(newPup)

	session.commit()