def map_row(self, row, metadata=None): pet = Pet() pet.id = row[0] pet.name = row[1] pet.birthDate = row[2] pet.type = row[3] return pet
def add_pet(): info = {'result': 0, 'msg': "成功", 'data': 'null'} json_data = json.loads(request.get_data()) pet_id = uuid.uuid1() img_url = json_data['ImgUrl'] img_list = ",".join(json_data['ImgList']) pet_name = json_data['PetName'] pet_type = json_data['PetType'] pet_sex = json_data['PetSex'] pet_old = json_data['PetOld'] pet_ster = json_data['PetSter'] pet_immune = json_data['PetImmune'] pet_feature = ",".join(json_data['PetFeature']) pet_description = json_data['PetDescription'] area = json_data['area'] phone = json_data['phone'] p = Pet(pet_code=pet_id, img_url=img_url, img_list=img_list, pet_name=pet_name, pet_type=pet_type, pet_sex=pet_sex, pet_old=pet_old, pet_ster=pet_ster, pet_immune=pet_immune, pet_feature=pet_feature, pet_description=pet_description, pet_area=area, pet_master_phone=phone) db.session.add(p) db.session.commit() return jsonify(info)
def add_pet(): """Pet add form; handle adding.""" form = AddPetForm() # print("LOOOOOOOKKKKKK!!!!") # import pdb # pdb.set_trace() if form.validate_on_submit(): name = form.name.data species = form.species.data photo_url = form.photo_url.data age = form.age.data notes = form.notes.data pet = Pet(name=name, species=species, photo_url=photo_url, age =age, notes=notes) db.session.add(pet) db.session.commit() flash("You just added {pet.name}") return redirect("/") else: return render_template( "add_pet.html", form=form)
def load_pets(): """Load pets into database.""" print "Loading pets..." Pet.query.delete() for row in open("seed_data/pet.data"): row = row.rstrip() name, age, gender, size, color, breed, animal_type, owner_id, is_available, character_details, health_details, image = row.split( "|") pet = Pet(name=name, age=age, gender=gender, size=size, color=color, breed=breed, animal_type=animal_type, owner_id=owner_id, is_available=is_available, character_details=character_details, health_details=health_details, image_url=image) db.session.add(pet) db.session.commit()
def add_pet(): """shows add pet form and handles submission of new pet""" form = AddPetForm() if form.validate_on_submit(): name = form.name.data species = form.species.data photo_url = form.photo_url.data age = form.age.data notes = form.notes.data available = form.available.data pet = Pet(name=name, species=species, photo_url=photo_url, age=age, notes=notes, available=available) db.session.add(pet) db.session.commit() return redirect('/') else: return render_template('add.html', form=form)
def home_page(): # Grab all the pets as a list of dictionary for pets (key word arguments) and load to the database. list_pets = get_pets(params) for pet_dict in list_pets: pet = Pet(**pet_dict) # Unloads the keyword arguments db.session.add(pet) db.session.commit() pets = Pet.query.filter_by(available = True) return render_template("home.html", pets=pets)
def add_pets(): form = PetForm() if form.validate_on_submit(): new = Pet(name=form.name.data, species=form.species.data, photo_url=form.photo_url.data, age=form.age.data, notes=form.notes.data) db.session.add(new) db.session.commit() return redirect('/') else: return render_template("add_pets.html", form=form)
def add_pet(): """Add a pet.""" form = AddPetForm() if form.validate_on_submit(): data = {k: v for k, v in form.data.items() if k != "csrf_token"} new_pet = Pet(**data) # new_pet = Pet(name=form.name.data, age=form.age.data, ...) db.session.add(new_pet) db.session.commit() flash(f"{new_pet.name} added.") return redirect(url_for('home_page')) else: # re-present form for editing return render_template("pet_add_form.html", form=form)
def add_pet(): """routes for add a pet form""" form = PetForm() if form.validate_on_submit(): name = form.name.data species = form.species.data image_url = form.image_url.data age = form.age.data notes = form.notes.data pet = Pet(name=name, species=species, image_url=image_url, age=age, notes=notes) db.session.add(pet) db.session.commit() return redirect('/') else: return render_template("pet-form.html", form=form)
def create_pet_object(pet_entry): """ :param pet_entry: ordered dictionary JSON object containing pet attributes. Assumes keys will be present: pet_id shelter_id lastUpdate pet_type description Takes pet attributes out of dictionary content and instantiates a Pet object.""" new_pet = Pet(pet_id=pet_entry['id'], shelter_id=pet_entry['shelterId'], pet_name=pet_entry['name'], last_update=pet_entry['lastUpdate'], pet_description=pet_entry['description'], pet_type=pet_entry['animal']) db.session.add(new_pet) db.session.commit() print("Added a Pet!")
def add_pet_profile(): """ Create pet profile. Adds pet profile to database and, if available for adoption, adds pet to adoption table. """ # also not working # user_id = User.query.get(session["user_id"]) name = request.form.get("name") species = request.form.get("species") age = request.form.get("age") breed = request.form.get("breed") gender = request.form.get("gender") details = request.form.get("details") adoptable = request.form.get("adoptable") pet = Pet(user_id=session["user_id"], name=name, species=species, age=age, breed=breed, gender=gender, details=details) db.session.add(pet) db.session.commit() if adoptable: pet_id = pet.pet_id owner_id = pet.user_id adoption = Adoption(pet_id=pet_id, owner_id=owner_id) db.session.add(adoption) db.session.commit() flash("Your pet is now available for adoption!") flash("Your pet's profile has been created!") return redirect("pets/" + str(pet_id))
def load_pets_csv(): """Load pets into database from csv file.""" print "Loading pets..." Pet.query.delete() with open('seed_data/pets.csv') as pet_csvfile: readPets = csv.reader(pet_csvfile, delimiter=',') for row in readPets: name = row[0] age = row[1] gender = row[2] size = row[3] color = row[4] breed = row[5] animal_type = row[6] owner_id = row[7] is_available = row[8] character_details = row[9] health_details = row[10] image_url = row[11] pet = Pet(name=name, age=age, gender=gender, size=size, color=color, breed=breed, animal_type=animal_type, owner_id=owner_id, is_available=is_available, character_details=character_details, health_details=health_details, image_url=image_url) db.session.add(pet) db.session.commit()
def load_pets(): """Load pets from pets_data into database.""" print "Pets" Pet.query.delete() for row in open("data/pets_data"): row = row.rstrip() user_id, name, species, age, breed, gender, details, picture = row.split( "|") pet = Pet(user_id=user_id, name=name, species=species, age=age, breed=breed, gender=gender, details=details, picture=picture) db.session.add(pet) db.session.commit()
"""Seed file to make test pets""" from model import Pet, db from app import app #create all tables db.drop_all() db.create_all() #If table isn't empty, then empty it Pet.query.delete() #add users bp = Pet(name="BP", species="Cat", image_url="http://placekitten.com/200", available=True) buddy = Pet(name="Buddy", species="Cat", image_url="https://placekitten.com/200", available=True) sparky = Pet(name="Sparky", species="Dog", image_url="https://placedog.net/200", available=True) rainbow = Pet(name="Rainbow", species="Fish", image_url="https://picsum.photos/200", available=True) #add to db