Пример #1
0
def editdog():
    validation_check = Dog.validate_dog(request.form)
    if "_flashes" in session.keys() or not validation_check:
        return redirect("/myaccount")
    else:
        edit_dog = Dog.edit_dog(request.form)
        return redirect("/myaccount")
Пример #2
0
class GenericsTest(TestCase):

    def setUp(self):

        self.mew = Cat(name="mew")
        self.mew.save()

        self.snoopy = Dog(name="snoopy")
        self.snoopy.save()

        cat_house = AnimalHouse(animal=self.mew)
        cat_house.save()

        dog_house = AnimalHouse(animal=self.snoopy)
        dog_house.save()

    def test_polymorphic_calls(self):

        houses = AnimalHouse.objects.all()

        self.assertEquals(houses[0].animal.make_sound(), "meow!")
        self.assertEquals(houses[1].animal.make_sound(), "guau!")

    def test_generic_filter(self):        

        cat_houses = AnimalHouse.objects.filter(content_type=ContentType.objects.get_for_model(Cat))
        self.assertEquals([house.animal for house in cat_houses], [self.mew])

        dog_houses = AnimalHouse.objects.filter(content_type=ContentType.objects.get_for_model(Dog))
        self.assertEquals([house.animal for house in dog_houses], [self.snoopy])
        
Пример #3
0
def addadog():
    validation_check = Dog.validate_dog(request.form)
    if "_flashes" in session.keys() or not validation_check:
        return redirect("/dashboard")
    else:
        new_dog = Dog.add_dog(request.form)
        return redirect("/dashboard")
Пример #4
0
def populate_dogs():
    name = [
        "Fido", "Dashi", "Ian", "Jorge", "Martin", "Igor", "Alina", "Miraf",
        "Cedes", "Karly"
    ]
    breed = [
        "German Shepherd", "French Bulldog", "Maltese", "Great Dane",
        "Shi Tzu", "Pug", "Greyhound"
    ]
    gender = ["Male", "Female"]
    age = ["Puppy", "Adolecsent", "Adult", "Senior"]
    size = ["Toy", "Small", "Medium", "Large", "Extra Large"]
    socialLevel = ["Shy", "Social"]
    activityLevel = ["Not Active", "A Little Active", "Active", "Very Active"]
    ownerEmail = "*****@*****.**"
    dgs = []
    for i in range(10):
        dog = Dog(name=choice(name),
                  breed=choice(breed),
                  gender=choice(gender),
                  age=choice(age),
                  size=choice(size),
                  socialLevel=choice(socialLevel),
                  activityLevel=choice(activityLevel),
                  ownerEmail=ownerEmail)
        dgs.append(dog.put())
    up = UserProfile(name="Testo Mondongo",
                     email=ownerEmail,
                     dogs=dgs,
                     city="San Juan",
                     state="Puerto Rico")
    up.put()
Пример #5
0
def deleteDogs():
	selected_dogs = []
	for dog in Dog.select().where(Dog.breed == "cat"):
		selected_dogs.append(model_to_dict(dog))
		print(model_to_dict(dog))
	
	query = Dog.delete().where(Dog.breed == "cat")
	print(query.execute(), "rows deleted")

	return jsonify(selected_dogs)
Пример #6
0
def Dogs():
    dogs = Dog()
    if request.method == "GET":
        return dogs.getAllDogs()
    elif request.method == "POST":
        print request.json.keys()
        name = request.json["name"]
        notes = request.json["notes"]
        owner = request.json["owner"]
        print name, notes, owner
        dogs.insert(0, name, notes, owner)
        return json.dumps({"sucess": True})
def create():

    errors = Dog.validate(request.form)

    if errors:
        for e in errors:
            flash(e)
    else:
        new_dog = Dog.create(request.form)
        print(new_dog.name)
        return redirect("/")

    return redirect("/")
Пример #8
0
def create_dog(email, name, breed, gender, age, size, social, active,
               profilePic):
    p = get_user_profile(email)
    newDog = Dog(name=name,
                 breed=breed,
                 age=age,
                 gender=gender,
                 socialLevel=social,
                 activityLevel=active,
                 size=size,
                 ownerEmail=email,
                 profilePic=profilePic)
    newKey = newDog.put()
    p.dogs.append(newKey)
    p.put()
Пример #9
0
def getDog():
	found_dog = Dog.get_by_id(3)
	# found_dog = Dog.get(Dog.id == 3)

	print(model_to_dict(found_dog))

	return jsonify(model_to_dict(found_dog))
Пример #10
0
def getDogs():
	selected_dogs = []
	for dog in Dog.select().where(Dog.breed == "cat"):
		selected_dogs.append(model_to_dict(dog))
		print(model_to_dict(dog))

	return jsonify(selected_dogs)
Пример #11
0
    def setUp(self):

        self.mew = Cat(name="mew")
        self.mew.save()

        self.snoopy = Dog(name="snoopy")
        self.snoopy.save()

        cat_house = AnimalHouse(animal=self.mew)
        cat_house.save()

        dog_house = AnimalHouse(animal=self.snoopy)
        dog_house.save()
Пример #12
0
def updateDog():
	found_dog = Dog.get_by_id(2)

	name = found_dog.name
	owner = found_dog.owner
	age = request.json['age']
	breed = found_dog.breed

	payload = {
		"name": name,
		"owner": owner,
		"age": age,
		"breed": breed
	}
	print("payload: ", payload)

	num_updated = Dog.update(**payload).where(Dog.id == 2).execute()
	print("number of dogs updated", num_updated)

	found_dog = Dog.get_by_id(2)
	
	return jsonify(model_to_dict(found_dog))
Пример #13
0
def create():
    print(request.form)
    if len(request.form["name"]) < 1:
        flash("Name fields are required", category="name")
        flash("Dont be a dingus", category="name")
    errors = get_flashed_messages(with_categories=True)
    if errors:
        print(json.dumps(errors))
        return jsonify(errors=errors)

    else:
        new_dog = Dog.create(request.form)
        db.session.add(new_dog)
        db.session.commit()
    return redirect("/")
Пример #14
0
def dog(dog_id):
    dog = Dog()
    if request.method == "GET":
        return dog.getDog(dog_id)
    if request.method == "PUT":
        print request.json
        Name = request.json["name"]
        Notes = request.json["notes"]
        Owner = request.json["owner"]
        dog.update(dog_id, Name, Notes, Owner)
        return json.dumps({"sucess": True})
    if request.method == "DELETE":
        dog.deleteDog(dog_id)
        return json.dumps({"sucess": True})
Пример #15
0
def createDog():
	name = request.json['name']
	owner = request.json['owner']
	age = request.json['age']
	breed = request.json['breed']

	payload = {
		"name": name,
		"owner": owner,
		"age": age,
		"breed": breed
	}

	dog = Dog.create(**payload)

	print(model_to_dict(dog))
	
	return jsonify(model_to_dict(dog))
def create():

    if len(request.form['name']) < 1:
        flash("Name field is required", category="name")

    if len(request.form['breed']) < 1:
        flash("Breed field is required", category="breed")

    if len(request.form['weight']) < 1:
        flash("Weight field is required", category="weight")

    errors = get_flashed_messages(with_categories=True)
    print(errors)

    if errors:
        # return errors as json
        return jsonify({"errors": errors})

    new_dog = Dog.create(request.form)
    # db.session.add(new_dog)
    # db.session.commit()
    return redirect("/dogs")
Пример #17
0
def demo_dog(user_id):
    from models import Dog
    dog = Dog.query.filter(Dog._name=='Pluto', Dog.user_id==user_id).first()
    creation_date = today - timedelta(days=7)
    weight = 25
    goal_weight = 30
    birthday = datetime.strptime('07012016', '%m%d%Y')
    filename = 'Pluto.jpg'
    url = '/static/img/demo/Pluto.jpg'
    thumbnail_url = '/static/img/demo/Pluto-thumbnail.jpg'
    if dog is None:
        dog = Dog('Pluto', 'Lab Mix', birthday, 'lb', weight, goal_weight, creation_date.date(), user_id, filename, url, thumbnail_url)
    else:
        dog._name = 'Pluto'
        dog._breed = 'Lab Mix'
        dog._birthday = birthday
        dog._current = weight
        dog._goal = goal_weight
        dog._metric = 'lb'
        dog._date = creation_date.date()
        dog.user_id = user_id
        dog._image_url = url
        dog._image_filename = filename
    db.session.add(dog)
    db.session.commit()
    return dog
Пример #18
0
def create(request):
    print request.POST
    dog = Dog(name=request.POST['name'],breed=request.POST['breed'])
    dog.save()
    return redirect('/')
Пример #19
0
def dummy_db_data():
    # Deleting all existing users will cause ids to change
    safe_add_user(User(email="*****@*****.**",
            password=sha256_crypt.hash("123456"),
            first_name="Fahd",
            last_name="Chaudhry",
            date_of_birth="01/02/1999",
            city = 'Burnaby',
            willing_to_walk = "Yes",
            latitude='49.269914',
            longitude='-122.954904'))

    safe_add_user(User(email="*****@*****.**",
            password=sha256_crypt.hash("123456"),
            first_name="Siddharth",
            last_name="Chugh",
            date_of_birth="01/02/1999",
            city = 'West Vancouver',
            willing_to_walk = "No",
            latitude='49.328625',
            longitude='-123.160198'))

    safe_add_user(User(email="*****@*****.**",
            password=sha256_crypt.hash("123456"),
            first_name="User",
            last_name="One",
            date_of_birth="01/02/1999",
            city = 'Vancouver',
            willing_to_walk = "Yes",
            latitude='49.26967',
            longitude='-123.07725'))

    safe_add_user(User(email="*****@*****.**",
            password=sha256_crypt.hash("123456"),
            first_name="User",
            last_name="Two",
            date_of_birth="01/02/1999",
            city = 'Vancouver',
            willing_to_walk = "Yes",
            latitude='49.26866',
            longitude='-123.07865'))

    safe_add_user(User(email="*****@*****.**",
            password=sha256_crypt.hash("123456"),
            first_name="User",
            last_name="Three",
            date_of_birth="01/02/1999",
            city = 'Vancouver',
            willing_to_walk = "Yes",
            latitude='49.26773',
            longitude='-123.07707'))
    
    userA = User.query.filter_by(email="*****@*****.**").first()
    userB = User.query.filter_by(email="*****@*****.**").first()
    user1 = User.query.filter_by(email="*****@*****.**").first()
    user2 = User.query.filter_by(email="*****@*****.**").first()
    user3 = User.query.filter_by(email="*****@*****.**").first()
    
    # Dummy data for dog1 for fahd
    safe_add_dog(Dog(name="Rover",
                age=7,
                breed="German Shepherd",
                owner="*****@*****.**"
                ))

    # Dummy data for dog2 for Fahd
    safe_add_dog(Dog(name="Coco",
                age=4,
                breed="German Shepherd",
                owner="*****@*****.**"
                ))
    safe_add_dog(Dog(name="Lily",
                age=4,
                breed="Golden Retriever",
                owner=userB.email
                ))
    safe_add_dog(Dog(name="Rusty",
                age=2,
                breed="Corgi",
                owner="*****@*****.**"
                ))

    safe_add_dog(Dog(name="Petunia",
                age=8,
                breed="Chihuahua",
                owner="*****@*****.**"
                ))
    safe_add_dog(Dog(name="Buster",
                age=3,
                breed="Pit bull",
                owner="*****@*****.**"
                ))
    safe_add_dog(Dog(name="Dorsen",
                age=1,
                breed="Samoyed",
                owner="*****@*****.**"
                ))
    safe_add_dog(Dog(name="Rex",
                age=2,
                breed="Dalmatian",
                owner="*****@*****.**"
                ))

    safe_add_review(Review(
                rating=5,
                title="Love 'em",
                comment='''Simply amazing. He is
                a genius at walking dogs. I have 101 beautiful dalmatians, and
                he was able to walk them all at once. I swear their coats are
                shinier than ever. Amazing worker.
                ''',
                authorid=userB.id,
                receiverid=userA.id
                ))
    safe_add_review(Review(
                rating=3,
                title="Meh",
                authorid=user1.id,
                receiverid=userA.id
                ))
    safe_add_review(Review(
                rating=3,
                title="Meh meh",
                comment="asdfasdf",
                authorid=user2.id,
                receiverid=userB.id
                ))
    safe_add_review(Review(
                rating=5,
                title="Great",
                comment="I think they're great",
                authorid=userB.id,
                receiverid=user1.id
                ))
    safe_add_review(Review(
                rating=4,
                title="Not bad",
                comment="Not bad at all",
                authorid=user3.id,
                receiverid=user1.id
                ))
    delete_all(Event)
    event1 = Event(
                title="Walked Fahd's dog",
                body="walked coco",
                city="Vancouver",
                latitude="49.2608724",
                longitude="-123.1139529",
                author=user1.email)
    event2 = Event(
                title="Walked Fahd's dog",
                body="walked rover",
                city="Vancouver",
                latitude="49.2608724",
                longitude="-123.1139529",
                author=user2.email)
    event3 = Event(
                title="Met user 2",
                body="we talked about dog walking",
                city="Vancouver",
                latitude="49.2608724",
                longitude="-123.1139529",
                author=user3.email)
    event4 = Event(
                title="Met user 3",
                body="we talked about dogs",
                city="Vancouver",
                latitude="49.2608724",
                longitude="-123.1139529",
                author=userB.email)
    event5 = Event(
                title="Met user 1",
                body="We decided on a dog walking schedule.",
                city="Vancouver",
                latitude="49.2608724",
                longitude="-123.1139529",
                author=userA.email)
    event6 = Event(
                title="Took Rover to the vet",
                body="I was worried!",
                city="Vancouver",
                latitude="49.2608724",
                longitude="-123.1139529",
                author=userA.email)
    db.session.add(event1)
    db.session.add(event2)
    db.session.add(event3)
    db.session.add(event4)
    db.session.add(event5)
    db.session.add(event6)
    db.session.commit()
Пример #20
0
def delete_a_dog():
    delete_a_dog = Dog.delete_dog(request.form)
    return redirect("/myaccount")
Пример #21
0
def get_dog_by_id(ids):
    dogs = Dog.query(Dog.key == ids).fetch(1)
    for dog in dogs:
        return dog
    return None
Пример #22
0
def create_dog(breed, lifespan, miniature):
  miniature = bool(miniature)
  dog = Dog(breed=breed, lifespan=lifespan, miniature=miniature)
  db.session.add(dog)
  db.session.commit()
  return jsonify(dog.as_dict())
def create():
    print(request.form)
    new_dog = Dog.create(request.form)
    db.session.add(new_dog)
    db.session.commit()
    return redirect("/")