def edit_animal(id): name = request.form["name"] dob = request.form["dob"] animal_type = request.form["animal_type"] treatment_notes = request.form["notes"] owner = owner_repository.select_owner(request.form["owner_id"]) vet = vet_repository.select_vet(request.form["vet_id"]) new_animal = Animal(name, dob, animal_type, owner, treatment_notes, vet, id) animal_repository.update_animal(new_animal) return redirect('/animals/'+id+'/more')
def select_all_animals(): results = run_sql("SELECT * FROM animals WHERE archived=%s", ["FALSE"]) animals = [] for result in results: owner = owner_repository.select_owner(result["owner_id"]) vet = vet_repository.select_vet(result["vet_id"]) animal = Animal(result["name"], result["date_of_birth"], result["animal_type"], owner, result["treatment_notes"], vet, result["id"]) animals.append(animal) return animals
def select_animal(id): sql = "SELECT * FROM animals WHERE id=%s" value = [id] result = run_sql(sql, value)[0] if result is not None: owner = owner_repository.select_owner(result["owner_id"]) vet = vet_repository.select_vet(result["vet_id"]) animal = Animal(result["name"], result["date_of_birth"], result["animal_type"], owner, result["treatment_notes"], vet, result["id"]) return animal
def more_owner_info(id): owners = owner_repository.select_all_owners() print(len(owners)) owners = sorted(owners, key=lambda owner: owner.name) chosen_owner = owner_repository.select_owner(id) animals = owner_repository.get_all_animals(chosen_owner) return render_template('/owners/index.html', animals=animals, more_info=True, chosen_owner=chosen_owner, owners=owners)
def edit_owner_page(id): chosen_owner = owner_repository.select_owner(id) owners = owner_repository.select_all_owners() owners = sorted(owners, key=lambda owner: owner.name) animals = owner_repository.get_all_animals(chosen_owner) return render_template('owners/index.html', animals=animals, owners=owners, more_info=True, edit_info=True, chosen_owner=chosen_owner)
def add_new_animal(): name = request.form["name"].capitalize() dob = request.form["dob"] dob = "2021-02-04" dob = dob.split('-') if len(dob)==3: if len(dob[1]) <2: dob[1] = "0" + dob[1] dob = dob[2]+"/"+dob[1]+"/"+dob[0] animal_type = request.form["animal_type"].capitalize() treatment_notes = request.form["notes"].capitalize() owner = owner_repository.select_owner(request.form["owner_id"]) vet = vet_repository.select_vet(request.form["vet_id"]) new_animal = Animal(name, dob, animal_type, owner, treatment_notes, vet) animal_repository.save_new_animal(new_animal) return redirect('/animals')
vet_3) animal_4 = Animal("Gerry", "13/2/2020", "Giraffe", owner_4, "Easy to find in a busy shop", vet_4) vet_repository.save_new_vet(vet_1) vet_repository.save_new_vet(vet_2) vet_repository.save_new_vet(vet_3) vet_repository.save_new_vet(vet_4) owner_repository.save_new_owner(owner_1) animal_repository.save_new_animal(animal_1) owner_repository.save_new_owner(owner_2) animal_repository.save_new_animal(animal_2) owner_repository.save_new_owner(owner_3) animal_repository.save_new_animal(animal_3) owner_repository.save_new_owner(owner_4) animal_repository.save_new_animal(animal_4) animal_repository.save_new_animal(animal_5) # vet_repository.update_vet(vet_1) # owner_repository.update_owner(owner_1) # animal_repository.update_animal(animal_1) print(animal_repository.select_animal(1)) print(vet_repository.select_vet(1)) print(owner_repository.select_owner(1)) print(animal_repository.select_all_animals()) print(owner_repository.select_all_owners()) print(vet_repository.select_all_vets())
def delete_owner_page(id): owner = owner_repository.select_owner(id) owner_repository.archive_owner(owner) return redirect('/owners')