def setUp(self): test_vet_peter = Vet("Peter", False) test_vet_mark = Vet("Mark", False) test_vet_paul = Vet("Paul", False) test_owner_david = Owner("David", "Edinburgh", False) test_owner_carl = Owner("Carl", "liverpool", False) test_owner_jamie = Owner("Jamie", "Glasgow", False) test_owner_sarah = Owner("Sarah", "London", False) self.test_animal_pepper = Animal("Pepper", "10/11/2015", "Horse", test_owner_david, test_vet_paul, False) self.test_animal_luna = Animal("Mika", "01/03/2012", "Cat", test_owner_david, test_vet_mark, False) self.test_animal_buddy = Animal("Buddy", "19/01/2014", "Rabbit", test_owner_carl, test_vet_peter, False) self.test_animal_snowy = Animal("Snowy", "17/02/2015", "Dog", test_owner_carl, test_vet_peter, False) self.test_animal_lola = Animal("Lola", "04/08/2018", "Cow", test_owner_jamie, test_vet_peter, False) self.test_animal_apollo = Animal("Apollo", "22/03/2016", "Dog", test_owner_jamie, test_vet_paul, False) self.test_animal_buster = Animal("Buster", "29/04/2019", "Dog", test_owner_sarah, test_vet_paul, False) self.test_animal_izzy = Animal("Izzy", "30/05/2020", "Cat", test_owner_sarah, test_vet_mark, False)
def setUp(self): self.vet_1 = Vet("John", "Smith") self.owner_1 = Owner("Cpt.", "Jack", "Harkness", "07411000000", True) self.animal_1 = Animal("Tigger", datetime.date(2019, 5, 1), "Tiger", self.owner_1) self.animal_2 = Animal("Roger", datetime.date(2018, 7, 2), "Rabbit", self.owner_1, self.vet_1)
def select_all_vets(): results = run_sql("SELECT * FROM vets WHERE archived=%s", ["FALSE"]) vets = [] for result in results: vet = Vet(result["name"], result["id"]) vets.append(vet) return vets
def create_vet(): first_name = request.form['first_name'] last_name = request.form['last_name'] license = request.form['license'] vet = Vet(first_name, last_name, license) vet_repository.save(vet) return redirect('/vets')
def update_vet(id): first_name = request.form['first_name'] last_name = request.form['last_name'] license = request.form ['license'] vet = Vet(first_name, last_name, license, id) vet_repository.update(vet) return redirect('/vets')
def select(id): sql = 'SELECT * FROM vets WHERE id = %s' values = [id] result = run_sql(sql, values)[0] vet = Vet(result['first_name'], result['last_name'], result['license'], result['id']) return vet
def update_vet(id): first_name = request.form['first_name'] last_name = request.form['last_name'] img_url = request.form['img_url'] if request.form['img_url'] else "static/images/no_img.jpg" updated_vet = Vet(first_name, last_name, img_url, id) vet_repository.update(updated_vet) return redirect(f'/vets/{updated_vet.id}')
def create(): first_name = request.form["first_name"] last_name = request.form["last_name"] max_animals = request.form["max_animals"] vet = Vet(first_name, last_name, max_animals) vet_repository.save(vet) return redirect("/vets")
def new(): if request.method == 'GET': return render_template("vets/new.html.j2") if request.method == 'POST': name = request.form['name'] deactivated = False if name != "": vet = Vet(name, deactivated) saved_vet = vet_repository.save(vet) if saved_vet.id != None: message = f"Success {saved_vet.name} added" else: message = "Failure" if request.form['action'] == "finish": return redirect(url_for("vets.index", message=message)) elif request.form['action'] == "continue": return render_template("vets/new.html.j2", message=message) else: message = "Malformed URL" return redirect(url_for("vets.index", message=message)) else: return redirect(url_for("vets.index")) else: message = "Error finding or displaying page" return redirect(url_for("index", message=message))
def create_new_vet(): first_name = request.form['first_name'] last_name = request.form['last_name'] img_url = request.form['img_url'] if request.form['img_url'] else "static/images/no_img.jpg" new_vet = Vet(first_name, last_name, img_url) vet_repository.save(new_vet) return redirect('/vets')
def select_vet(id): sql = "SELECT * FROM vets WHERE id=%s" value = [id] result = run_sql(sql, value)[0] if result is not None: vet = Vet(result["name"], result["id"]) return vet
def setUp(self): self.vet = Vet("Dr. Daisuke Serizawa") self.kaiju_1 = Kaiju("Godzilla", "1954", "Sea monster", "Oxygen Destroyer", self.vet, True) self.kaiju_2 = Kaiju("Shin_Godzilla", "2016", "Sea monster", "Oral coagulant injection (10000 litres plus)", self.vet, True)
def update(id): # vet = vet_repository.select(id) first_name = request.form["first_name"] last_name = request.form["last_name"] max_animals = request.form["max_animals"] vet = Vet(first_name, last_name, max_animals, id) vet_repository.update(vet) return redirect(f"/vets/{id}")
def setUp(self): self.vet = Vet("Tim Sinnott") self.kaiju_1 = Kaiju( "Biollante", "1989", "Genetically-modified Rose/Crocodile/Ghost of a death girl kaiju hybrid", "Finding peace while simultaneously exploding", self.vet, True) self.kaiju_2 = Kaiju("Destoroyah", "1995", "Sea monster", "Godzilla in meltdown mode", self.vet, False)
def select_all(): vets = [] sql = "SELECT * FROM vets" results = run_sql(sql) for row in results: vet = Vet(row['name'], row['contact'], row['id']) vets.append(vet) return vets
def select(id): vet = None sql = "SELECT * FROM vets WHERE id = %s" values = [id] results = run_sql(sql, values)[0] if results is not None: vet = Vet(results['name'], results['contact'], results['id']) return vet
def select_all(): vets = [] sql = 'SELECT * FROM vets' results = run_sql(sql) for result in results: vet = Vet(result['first_name'], result['last_name'], result['license'], result['id']) vets.append(vet) return vets
def select(self, id): vet = None sql = f"SELECT * FROM {self.table} " + "WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: vet = Vet(result["first_name"], result["last_name"], result['id']) return vet
def _select_vet(self, id): vet = None sql = "SELECT * FROM vets WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: vet = Vet(result["first_name"], result["last_name"], result['id']) return vet
def select_id(id): vet = None sql = "SELECT * FROM vets WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: vet = Vet(result['name'], result['deactivated'], result['id']) return vet
def select_all_vets(): vet_list = [] sql = "SELECT * FROM vets" results = run_sql(sql) for row in results: vet = Vet(row['name'], row['id']) vet_list.append(vet) return vet_list
def select_all_active(deactivated=False): vets = [] sql = "SELECT * FROM vets WHERE deactivated = %s" values = [deactivated] results = run_sql(sql, values) for row in results: vet = Vet(row['name'], row['deactivated'], row['id']) vets.append(vet) return vets
def setUp(self): owner = Owner('Jack', 'White', '*****@*****.**', '487239847', True, id=4) vet = Vet('White', 'Jack', 3) self.pet = Pet('Smokey', dt.date(2020, 7, 24), '', 'cat', owner, vet, 'randomString', 'dkfjd', 3)
def select(vet_id): sql = "SELECT * FROM vets WHERE id = %s" values = [vet_id] result = run_sql(sql, values) if result: vet_dict = result[0] vet = Vet(vet_dict['first_name'], vet_dict['last_name'], vet_dict['img_url'], vet_dict['id']) return vet
def select_all(): vets = [] sql = "SELECT * FROM vets" results = run_sql(sql) for row in results: vet = Vet(row['first_name'], row['last_name'], row['img_url'], row['id']) vets.append(vet) return vets
def setUp(self): owner = Owner('Jack', 'White', '*****@*****.**', '487239847', True, id=3) vet = Vet('White', 'Jack', 3) pet = Pet('dummy pet', dt.date(2020, 2, 2), '1', 'dog', owner, vet, 'dkfj', 'what', 2) treatment = Treatment('kadjf', 'a description', 1) self.pet_treatment = PetTreatment(pet, treatment, 3)
def select(vet_id): # Create the SQL query, pass in the data and run it sql = "SELECT * FROM vet WHERE id = %s" values = [vet_id] result = run_sql(sql, values) # Create object if data is found in the database if len(result) > 0: new_vet = Vet(result[0]['first_name'], result[0]['last_name'], result[0]['id']) return new_vet
def select_all(self, sort=False): vets = [] if sort: sql = f"SELECT * FROM {self.table} ORDER BY last_name ASC" else: sql = f"SELECT * FROM {self.table}" results = run_sql(sql) for row in results: vet = Vet(row["first_name"], row["last_name"], row['id']) vets.append(vet) return vets
def select_all(): # Create empty list to hold objects vets = [] # Create the SQL query, pass in the data and run sql = "SELECT * FROM vet" results = run_sql(sql) # Loop through the data for row in results: # Create new vet object and append it to the list new_vet = Vet(row['first_name'], row['last_name'], row['id']) vets.append(new_vet) return vets
def save(): # Grab data from request first_name = request.form['vet_first_name'] last_name = request.form['vet_last_name'] if len(first_name) > 48: return_error('av-1') # Return error code 1: First name too long elif len(last_name) > 48: return_error('av-2') # Return error code 2: Last name too long # Create new object to be saved vet = Vet(first_name, last_name) VR.save(vet) # Redirect the user return redirect('/vets')