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
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()
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 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})
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()
def create(request): print request.POST dog = Dog(name=request.POST['name'],breed=request.POST['breed']) dog.save() return redirect('/')
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()
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())