示例#1
0
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)