def view(id): # Get data for the correct pet pet = PR.select(id) notes = NR.select_by_pet(id) notes_length = len(notes) treatments = perscribed.select_by_pet(pet.id) treatments_length = len(treatments) appointments = AR.select_by_pet(id) appointment_length = len(appointments) for appointment in appointments: appointment.days_until() pet_dob_string = pet.convert_dob_to_text() return render_template('/pets/specific.html', title=pet.name + " - " + pet.pet_type.breed, pet_dob_string=pet_dob_string, pet=pet, notes=notes, notes_length=notes_length, treatments=treatments, treatments_length=treatments_length, appointments=appointments, appointment_length=appointment_length)
def add_appointment(id): # Pull data from db pet = PR.select(id) vets = VR.select_all() # Render html return render_template('pets/add-appointment.html', title='Create appointment for ' + pet.name, pet=pet, vets=vets)
def add_treatment(id): # Grab needed data pet = PR.select(id) treatments = TR.select_all() # Render page return render_template('pets/add-treatment.html', title='Add treatment to ' + pet.name, treatments=treatments, pet=pet)
def add_note(id): # Pull in the required data from other repos pet = PR.select(id) vets = VR.select_all() # Render the page return render_template('pets/add-note.html', title='Add a note to ' + pet.name, pet=pet, vets=vets)
def select(note_id): # Create the SQL query, pass in the data and run it sql = "SELECT * FROM note WHERE id = %s" values = [note_id] result = run_sql(sql, values) # Create object if data is found in the database if len(result) > 0: pet = PR.select(result[0]['pet_id']) vet = VR.select(result[0]['vet_id']) new_note = Note(result[0]['date'], result[0]['note_text'], pet, vet) return new_note
def save_treatment(id): # Pull in POST data treatment_id = request.form['treatment_id'] # Pull in database data pet = PR.select(id) treatment = TR.select(treatment_id) # Save to perscribed treatments perscribed_treatment = PerscribedTreatment(pet, treatment) perscribed.save(perscribed_treatment) return redirect('/pets/' + id)
def edit(id): # Pull in the required data from other repos pet = PR.select(id) owners = OR.select_all() vets = VR.select_all() pet_types = PTR.select_all() # Render the page return render_template('pets/edit.html', title='Edit Pet', pet=pet, owners=owners, vets=vets, pet_types=pet_types)
def save_note(id): note_date = request.form['note_date'] note_text = request.form['note_text'] vet_id = request.form['note_vet'] # Grab the data for the object pet = PR.select(id) vet = VR.select(vet_id) # Create the note object for saving note = Note(note_date, note_text, pet, vet) NR.save(note) # Redirect return redirect('/pets/' + id)
def save_from_pet(id): # Grab request data date = request.form['appointment_date'] note = request.form['appointment_note'] vet_id = request.form['appointment_vet'] # Grab needed objects vet = VR.select(vet_id) pet = PR.select(id) # Create object for saving appointment = Appointment(date, note, vet, pet, pet) AR.save(appointment) # Redirect return redirect('/pets/' + id)
def select(id): # Create SQL query, insert data and run sql = "SELECT * FROM appointment WHERE id = %s" values = [id] result = run_sql(sql, values) # Check result has returned something if len(result) > 0: # Grab secondary data vet = VR.select(result[0]['vet_id']) pet = PR.select(result[0]['pet_id']) # Create new object appointment = Appointment(result[0]['date'], result[0]['note'], vet, pet, result[0]['id']) return appointment
def select_all(): # Create list of note objects and set == empty list notes = [] # Create the SQL query && input data before running it sql = "SELECT * FROM note" results = run_sql(sql) # Loop through all the results and append the objects to a list for row in results: # Get the objects to create the note object pet = PR.select(row['pet_id']) vet = VR.select(row['vet_id']) # Create new note object && append to notes list new_note = Note(row['date'], row['note_text'], pet, vet, row['id']) notes.append(new_note) return notes
def select_all(id): # Create list of appointments == empty list appointments = [] # Create SQL query, pass in data && run sql = "SELECT * FROM appointment" results = run_sql(sql) # Loop through results for row in results: # Grab secondary data vet = VR.select(row['vet_id']) pet = PR.select(row['pet_id']) # Create new object appointment = Appointment(row['date'], row['note'], vet, pet, row['id']) appointments.append(appointment) return appointments
def edit_pet(id): pet = pet_repository.select(id) vets = vet_repository.select_all() return render_template('pets/edit.html', pet=pet, all_vets=vets)
def show_pet(id): pet = pet_repository.select(id) return render_template('pets/show.html', pet=pet)