def update_animal(id): name = request.form['name'] species = request.form['species'] owner_id = request.form['owner_id'] owner = owner_repository.select(owner_id) animal = Animal(name, species, owner, id) animal_repository.update(animal) return redirect('/animals')
def detail(action, id): if request.method == 'GET': animals = animal_repository.select_all_by_owner_id(id) owner = owner_repository.select_id(id) len_animals = len(animal_repository.select_all_by_owner_id(id)) if action == "show": return render_template("owners/show.html.j2", owner=owner, len_animals=len_animals) elif action == "edit": return render_template("owners/edit.html.j2", owner=owner) elif action == "animals": return render_template("owners/detail.html.j2", owner=owner, len_animals=len_animals, animals=animals) elif action == "orphaned": animals = animal_repository.select_all_by_owner_id(1) active_owners = owner_repository.select_all_active() return render_template("owners/orphaned.html.j2", active_owners=active_owners, owner=owner, len_animals=len_animals, animals=animals) else: message = "Malformed URL" return redirect(url_for("owners.index", message=message)) if request.method == 'POST': if action == "delete": owner_repository.delete_id(request.form['id']) message = f"Owner: {owner.name} (id:{owner.id}) deleted" return redirect(url_for("owners.index", message=message)) elif action == "edit": name = request.form['name'] address = request.form['address'] try: deactivated = request.form['deactivated'] except: deactivated = False id = request.form['id'] owner = Owner(name, address, deactivated, id) owner_repository.update(owner) message = f"Owner: {owner.name} (id:{owner.id}) updated" return redirect(url_for("owners.index", message=message)) elif action == "deactivate": owner = owner_repository.select_id(id) animals = animal_repository.select_all_by_owner_id(id) for animal in animals: animal.owner = owner_repository.select_id(1) animal_repository.update(animal) owner.deactivated = True owner_repository.update(owner) message = f"All animals moved to No Owner, Owner {owner.name} deactivated, please reassign" return redirect(url_for("owners.index", message=message)) else: message = "Malformed URL" return redirect(url_for("owners.index", message=message))
def update_animal(id): name = request.form["name"] date_of_birth = request.form["date_of_birth"] animal_type = request.form["animal_type"] treatment_notes = request.form["treatment_notes"] owner = request.form["owner_id"] animal = Animal(name, date_of_birth, animal_type, treatment_notes, owner, id) animal_repository.update(animal) return redirect("/animals")
def detail(action, id): animal = animal_repository.select_id(id) len_treatments = len(treatment_repository.select_all_by_animal_id(id)) if request.method == 'GET': if action == "show": return render_template("animals/show.html.j2", animal=animal, len_treatments=len_treatments) elif action == "edit": active_vets = vet_repository.select_all_active() return render_template("animals/edit.html.j2", animal=animal, active_vets=active_vets) elif action == "treatments": treatments = treatment_repository.select_all_by_animal_id(id) return render_template("animals/detail.html.j2", animal=animal, len_treatments=len_treatments, treatments=treatments) else: message = "Malformed URL" return redirect(url_for("animals.index", message=message)) if request.method == 'POST': if action == "delete": animal_repository.delete_id(request.form['id']) message = f"Animal: {animal.name} (id:{animal.id}) deleted" return redirect(url_for("animals.index", message=message)) elif action == "edit": name = request.form['name'] dob = request.form['dob'] species = request.form['species'] owner_id = request.form['owner_id'] vet_id = request.form['vet_id'] try: deactivated = request.form['deactivated'] except: deactivated = False id = request.form['id'] vet = vet_repository.select_id(vet_id) owner = owner_repository.select_id(owner_id) animal = Animal(name, dob, species, owner, vet, deactivated, id) animal_repository.update(animal) message = f"Animal: {animal.name} (id:{animal.id}) updated" return redirect(url_for("animals.index", message=message)) elif action == "deactivate": animal = animal_repository.select_id(id) animal.owner = owner_repository.select_id(1) animal.deactivated = True animal_repository.update(animal) message = f"{animal.name} moved to No Owner, please reassign" # I want an if statment to make thsi work too: return redirect(url_for("owners.index", message=message)) return redirect(url_for("animals.index", message=message)) else: message = "Malformed URL" return redirect(url_for("animals.index", message=message))
def update(id): name = request.form['name'] type = request.form['type'] dob = request.form['dob'] owner_id = request.form['owner_id'] vet_id = request.form['vet_id'] owner = owner_repository.select(owner_id) vet = vet_repository.select(vet_id) animal = Animal(name, type, dob, owner, vet, id) animal_repository.update(animal) return redirect('/animals')
def update(id): name = request.form["name"] dob = request.form["dob"] species = request.form["species"] breed = request.form["breed"] owner = owner_repository.select(request.form["owner_id"]) vet = vet_repository.select(request.form["vet_id"]) date_registered = request.form["date_registered"] animal = Animal(name, dob, species, breed, owner, vet, date_registered, id) animal_repository.update(animal) return redirect(f"/animals/{id}")
def update_animal(id): name = request.form['name'] animal_type = request.form['animal_type'] dob_string = request.form['dob'] dob = datetime.datetime.strptime(dob_string, '%Y-%m-%d').date() owner_id = request.form['owner_id'] owner = owner_repository.select(owner_id) img_url = request.form['img_url'] if request.form[ 'img_url'] else "static/images/no_img.jpg" vet_id = None if request.form['vet_id'] == "None" else request.form[ 'vet_id'] vet = vet_repository.select(vet_id) updated_animal = Animal(name, dob, animal_type, owner, vet, img_url, id) animal_repository.update(updated_animal) return redirect(f'/animals/{updated_animal.id}')