def update(id): description = request.form["description"] days = request.form["duration_days"] hours = request.form["duration_hours"] minutes = request.form["duration_minutes"] duration = dh.time_delta(f"{days}:{hours}:{minutes}:00") days = request.form["recovery_days"] hours = request.form["recovery_hours"] minutes = request.form["recovery_minutes"] recovery = dh.time_delta(f"{days}:{hours}:{minutes}:00") cost = int(float(request.form["cost"]) * 100) animal = animal_repository.select(request.form["animal_id"]) old_treatment = treatment_repository.select(animal) animal.owner.decrease_bill(old_treatment.cost) treatment = Treatment(description, duration, recovery, cost, animal, id) if "start" in request.form: treatment.start_treatment() else: start = treatment_repository.select(animal).start treatment.start_treatment(start) animal.owner.increase_bill(treatment.cost) owner_repository.update(animal.owner) treatment_repository.update(treatment) return redirect(f"/animals/{animal.id}")
def update(id): name = request.form['name'] contact = request.form['contact'] address = request.form['address'] balance = request.form['balance'] owner = Owner(name, contact, address, balance, id) owner_repository.update(owner) return redirect("/owners")
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_owner(id): first_name = request.form['first_name'] last_name = request.form['last_name'] phone_num_1 = request.form['phone_num_1'] phone_num_2 = request.form['phone_num_2'] address = request.form['address'] owner = Owner(first_name, last_name, phone_num_1, phone_num_2, address, id) owner_repository.update(owner) return redirect('/owners')
def update(id): owner = owner_repository.select(id) first_name = request.form["first_name"] last_name = request.form["last_name"] num = request.form["num"] street = request.form["street"] city = request.form["city"] postcode = request.form["postcode"] address_id = request.form["address_id"] address = Address(num, street, city, postcode, address_id) address_repository.update(address) tel = request.form["tel"] email = request.form["email"] owner = Owner(first_name, last_name, address, tel, email, owner.bill, id) owner_repository.update(owner) return redirect(f"/owners/{id}")
def update(id): # Get data from request first_name = request.form['owner_first_name'] last_name = request.form['owner_last_name'] email = request.form['owner_email'] contact_no = request.form['owner_contact_number'] address = request.form['owner_address'] post_code = request.form['owner_post_code'] city = request.form['owner_city'] if len(first_name) > 48: return_error('eo-1') # Return error code 1: Firstname too long elif len(last_name) > 48: return_error('eo-2') # Return error code 2: Lastname too long elif len(email) > 100: return_error('eo-3') # Return error code 3: Email address too long elif len(contact_no) > 11: return_error('eo-4') # Return error code 4: Contact number too long elif len(address) > 100: return_error('eo-5') # Return error code 5: Address too long elif len(post_code) > 8: return_error('eo-6') # Return error code 6: Post code too long elif len(city) > 100: return_error('eo-7') # Return error code 7: City too long # check checkbox exists checkbox = request.form.get("owner_registered") if checkbox is not None: print("Found") registered = True print(registered) else: print("Not found") registered = False print(registered) # Create the updated object owner = Owner(first_name, last_name, email, contact_no, address, post_code, city, registered, id) OR.update(owner) return redirect('/owners/'+id)
def update_owner(id): name = request.form["name"] address = request.form["address"] owner = Owner(name, address, id) owner_repository.update(owner) return redirect("/owners")