def settings(): if request.method == 'GET': return render_template('settings.html.j2') if request.method == 'POST': if request.form['action'] == "delete_id": id = request.form['id'] if request.form['table'] == "vet": vet = vet_repository.select_id(id) vet_repository.delete_id(id) message = f"Vet {vet.name} {vet.id} deleted, and cascaded" elif request.form['table'] == "owner": owner = owner_repository.select_id(id) owner_repository.delete_id(id) message = f"Owner {owner.name} {owner.id} deleted, and cascaded" elif request.form['table'] == "animal": animal = animal_repository.select_id(id) animal_repository.delete_id(id) message = f"Vet {animal.name} {animal.id} deleted, and cascaded" elif request.form['action'] == "delete_all": if request.form['table'] == "vet": vet_repository.delete_all() message = "All Vets deleted, and cascaded" elif request.form['table'] == "owner": owner_repository.delete_all() message = f"All Owners deleted, and cascaded" elif request.form['table'] == "animal": animal_repository.delete_all() message = f"All Animals deleted, and cascaded" return render_template('settings.html.j2', message=message)
import pdb from models.animal import Animal from models.vet import Vet import repositories.animal_repository as animal_repository import repositories.vet_repository as vet_repository animal_repository.delete_all() vet_repository.delete_all() vet_1 = Vet("Dr Doolittle") vet_repository.save(vet_1) vet_2 = Vet("Dr Herriot") vet_repository.save(vet_2) vet_3 = Vet("Dr Hamster") vet_repository.save(vet_3) vet_4 = Vet("Dr Greene") vet_repository.save(vet_4) vet_repository.select_all() animal_1 = Animal("Spot", "Cat", "15-06-2005", "15", "Deep gash on nose to be treated", "Commander Data", "07922175003", "*****@*****.**", vet_1) animal_repository.save(animal_1) animal_2 = Animal("Twiggy", "Stick Insect", "10-10-2019", "1", "Leg pulled off by spider. Replacement leg needed", "David Bellamy", "07922175003", "*****@*****.**", vet_1) animal_repository.save(animal_2) animal_3 = Animal("Zeus", "Silverback", "17-10-1990", "30", "Ingrowing toenail, left pinky toe", "Jo Mobutu", "07922175003", "*****@*****.**", vet_3)
import repositories.pet_type_repository as PTR import repositories.owner_repository as OR import repositories.pet_repository as PR import repositories.note_repository as NR import repositories.vet_repository as VR import repositories.perscribed_treatments_repository as perscribed import repositories.treatment_repository as TR import repositories.appointment_repository as AR # Drop the data from the tables NR.delete_all() PR.delete_all() PTR.delete_all() perscribed.delete_all() OR.delete_all() VR.delete_all() TR.delete_all() # Create data # Pet Types pet_type_1 = PetType('Dog', 'Spaniel') PTR.save(pet_type_1) pet_type_2 = PetType('Dog', 'Boarder Collie') PTR.save(pet_type_2) pet_type_3 = PetType('Cat', 'Scottish Fold') PTR.save(pet_type_3) pet_type_4 = PetType('Horse', 'Clydesdale')