Пример #1
0
    def post_shelter(payload):

        try:
            data = request.get_json()

            name = data.get('name')
            city = data.get('city')
            state = data.get('state')
            address = data.get('address')
            phone = data.get('phone')

            if ((name == '') or (city == '') or (state == '')
                    or (address == '')):
                abort(422)

            shelter = Shelter(name=name,
                              city=city,
                              state=state,
                              address=address,
                              phone=phone)
            shelter.insert()
        except BaseException as e:
            print(e)
            abort(422)

        formatted_shelters = [shelter.format()]

        return jsonify({'success': True, 'shelters': formatted_shelters}), 200
Пример #2
0
    async def add_shelter(self, request):
        data = await request.json()
        shelter = Shelter(**data)
        shelter.save_to_db()

        return web.Response(status=201,
                            body=json.dumps(shelter.json()).encode('utf-8'),
                            content_type='application/json')
Пример #3
0
def newShelter():
    if request.method == 'POST':
        newShelter = Shelter(
            name = request.form['name'],
            address = request.form['address'],
            city = request.form['city'],
            state = request.form['state'],
            zipCode = request.form['zipcode'],
            website = request.form['website'],
            current_occupancy = request.form['occupancy'],
            maximum_capacity = request.form['capacity']
        )

        session.add(newShelter)
        session.commit()

        flash("New Shelter created!")
        return redirect(url_for('viewShelter', key = newShelter.id))

    else:
        return render_template(
            'new.html',
            viewType = "shelter",
            traits = Shelter.defaultTraits()
        )
Пример #4
0
def shelterAdd():
	if request.method == 'POST':		
		newItem = Shelter(name = request.form['name'])
		newItem.address = request.form['address']
		newItem.city = request.form['city']
		newItem.state = request.form['state']
		newItem.zipCode = request.form['zipCode']
		newItem.email = request.form['email']
		newItem.website = request.form['website']
		newItem.current_capacity = request.form['current_capacity']
		newItem.max_capacity = request.form['max_capacity']
		session.add(newItem)
		session.commit()
		flash("New shelter has been added.")
		return redirect(url_for('shelterList'))
	else:
		return render_template('shelteradd.html')
Пример #5
0
def newShelter():
    if request.method == 'POST':
        newShelter = Shelter(name=request.form['name'],
                             address=request.form['address'],
                             city=request.form['city'],
                             state=request.form['state'],
                             zipCode=request.form['zipcode'],
                             website=request.form['website'],
                             current_occupancy=request.form['occupancy'],
                             maximum_capacity=request.form['capacity'])

        session.add(newShelter)
        session.commit()

        flash("New Shelter created!")
        return redirect(url_for('viewShelter', key=newShelter.id))

    else:
        return render_template('new.html',
                               viewType="shelter",
                               traits=Shelter.defaultTraits())
Пример #6
0
def puppyPopulate():

    #Add Shelters
    shelter1 = Shelter(name="Oakland Animal Services",
                       address="1101 29th Ave",
                       city="Oakland",
                       state="California",
                       zipCode="94601",
                       website="oaklandanimalservices.org")
    session.add(shelter1)

    shelter2 = Shelter(name="San Francisco SPCA Mission Adoption Center",
                       address="250 Florida St",
                       city="San Francisco",
                       state="California",
                       zipCode="94103",
                       website="sfspca.org")
    session.add(shelter2)

    shelter3 = Shelter(name="Wonder Dog Rescue",
                       address="2926 16th Street",
                       city="San Francisco",
                       state="California",
                       zipCode="94103",
                       website="http://wonderdogrescue.org")
    session.add(shelter3)

    shelter4 = Shelter(name="Humane Society of Alameda",
                       address="PO Box 1571",
                       city="Alameda",
                       state="California",
                       zipCode="94501",
                       website="hsalameda.org")
    session.add(shelter4)

    shelter5 = Shelter(name="Palo Alto Humane Society",
                       address="1149 Chestnut St.",
                       city="Menlo Park",
                       state="California",
                       zipCode="94025",
                       website="paloaltohumane.org")
    session.add(shelter5)

    #Add Puppies

    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'
    ]

    puppy_images = [
        "http://pixabay.com/get/da0c8c7e4aa09ba3a353/1433170694/dog-785193_1280.jpg?direct",
        "http://pixabay.com/get/6540c0052781e8d21783/1433170742/dog-280332_1280.jpg?direct",
        "http://pixabay.com/get/8f62ce526ed56cd16e57/1433170768/pug-690566_1280.jpg?direct",
        "http://pixabay.com/get/be6ebb661e44f929e04e/1433170798/pet-423398_1280.jpg?direct",
        "http://pixabay.com/static/uploads/photo/2010/12/13/10/20/beagle-puppy-2681_640.jpg",
        "http://pixabay.com/get/4b1799cb4e3f03684b69/1433170894/dog-589002_1280.jpg?direct",
        "http://pixabay.com/get/3157a0395f9959b7a000/1433170921/puppy-384647_1280.jpg?direct",
        "http://pixabay.com/get/2a11ff73f38324166ac6/1433170950/puppy-742620_1280.jpg?direct",
        "http://pixabay.com/get/7dcd78e779f8110ca876/1433170979/dog-710013_1280.jpg?direct",
        "http://pixabay.com/get/31d494632fa1c64a7225/1433171005/dog-668940_1280.jpg?direct"
    ]

    #This method will make a random age for each puppy between 0-18 months(approx.) old from the day the algorithm was run.
    def CreateRandomAge():
        today = datetime.date.today()
        days_old = randint(0, 540)
        birthday = today - datetime.timedelta(days=days_old)
        return birthday

    #This method will create a random weight between 1.0-40.0 pounds (or whatever unit of measure you prefer)
    def CreateRandomWeight():
        return random.uniform(1.0, 40.0)

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

    for i, x in enumerate(female_names):
        new_puppy = Puppy(name=x,
                          gender="female",
                          dateOfBirth=CreateRandomAge(),
                          picture=random.choice(puppy_images),
                          shelter_id=randint(1, 5),
                          weight=CreateRandomWeight())
        session.add(new_puppy)
        session.commit()
Пример #7
0
    def populate(self):

        #Add Shelters
        shelter1 = Shelter(name="Oakland Animal Services",
                           address="1101 29th Ave",
                           city="Oakland",
                           state="California",
                           zipCode="94601",
                           website="oaklandanimalservices.org",
                           maximum_capacity=randint(25, 35))
        session.add(shelter1)

        shelter2 = Shelter(name="San Francisco SPCA Mission Adoption Center",
                           address="250 Florida St",
                           city="San Francisco",
                           state="California",
                           zipCode="94103",
                           website="sfspca.org",
                           maximum_capacity=randint(25, 35))
        session.add(shelter2)

        shelter3 = Shelter(name="Wonder Dog Rescue",
                           address="2926 16th Street",
                           city="San Francisco",
                           state="California",
                           zipCode="94103",
                           website="http://wonderdogrescue.org",
                           maximum_capacity=randint(25, 35))
        session.add(shelter3)

        shelter4 = Shelter(name="Humane Society of Alameda",
                           address="PO Box 1571",
                           city="Alameda",
                           state="California",
                           zipCode="94501",
                           website="hsalameda.org",
                           maximum_capacity=randint(25, 35))
        session.add(shelter4)

        shelter5 = Shelter(name="Palo Alto Humane Society",
                           address="1149 Chestnut St.",
                           city="Menlo Park",
                           state="California",
                           zipCode="94025",
                           website="paloaltohumane.org",
                           maximum_capacity=randint(25, 35))
        session.add(shelter5)
        session.commit()

        self.shelters.extend(
            [shelter1, shelter2, shelter3, shelter4, shelter5])

        # Add Adopters
        a_name = random.choice(adopter_names)
        adopter1 = Adopter(name=random.choice(adopter_names))
        removeAdopterName(a_name)
        session.add(adopter1)

        a_name = random.choice(adopter_names)
        adopter2 = Adopter(name=random.choice(adopter_names))
        removeAdopterName(a_name)
        session.add(adopter2)

        a_name = random.choice(adopter_names)
        adopter3 = Adopter(name=random.choice(adopter_names))
        removeAdopterName(a_name)
        session.add(adopter3)

        a_name = random.choice(adopter_names)
        adopter4 = Adopter(name=random.choice(adopter_names))
        removeAdopterName(a_name)
        session.add(adopter4)

        a_name = random.choice(adopter_names)
        adopter5 = Adopter(name=random.choice(adopter_names))
        removeAdopterName(a_name)
        session.add(adopter5)
        session.commit()

        self.adopters.extend(
            [adopter1, adopter2, adopter3, adopter4, adopter5])

        #Add Puppies
        print "Before Males: %s" % self.numShelters()

        for i, x in enumerate(male_names):
            new_profile = CreateProfile(x, "male")
            session.add(new_profile)

            shelter_id = self.CheckinPuppy()
            new_puppy = Puppy(shelter_id=shelter_id, profile=new_profile)

            new_puppy.adopters.append(self.ChooseAdopter())

            session.add(new_puppy)
            session.commit()

        print "Before Females: %s" % self.numShelters()
        for i, x in enumerate(female_names):
            new_profile = CreateProfile(x, "female")
            session.add(new_profile)

            shelter_id = self.CheckinPuppy()
            new_puppy = Puppy(shelter_id=shelter_id, profile=new_profile)

            new_puppy.adopters.append(self.ChooseAdopter())

            session.add(new_puppy)
            session.commit()
Пример #8
0
from models import Shelter
# from models import Animal
created_shelter = Shelter.create(name='Aurora Animal Shelter',
                                 city='Denver',
                                 address="3985 S. Grant St.",
                                 phone="818-055-3121")
Shelter.create(name='Doggie Days',
               city='Denver',
               address="3233 Middlesborough Blvd.",
               phone="818-345-0199")
Shelter.create(name='No Feline Left Behind',
               city='Denver',
               address="4242 Main St.",
               phone="818-069-3125")
Shelter.create(name='Animals For All',
               city='Denver',
               address="101 Main St.",
               phone="818-217-8238")
Shelter.create(name="Bennet's Birds",
               city='Denver',
               address="5965 Eagleway St.",
               phone="867-5309")

# created_animals = Animal.create(
#         name = 'Rover',
#         breed= 'Golden Retriever',
#         shelter= 1,
#         age=2,
#         gender= 'male',
#         photo= 'https://images.unsplash.com/photo-1536809188428-e8ecf663d0be?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60',
#         description = "Rover is a runner, give him room to run!"