def do_PUT(self): content_len = int(self.headers.get('content-length', 0)) post_body = self.rfile.read(content_len) post_body = json.loads(post_body) # Parse the URL (resource, id) = self.parse_url(self.path) success = False # Delete a single animal from the list if resource == "animals": update_animal(id, post_body) if resource == "customers": update_customer(id, post_body) if resource == "employees": update_employee(id, post_body) if resource == "locations": update_location(id, post_body) if success: self._set_headers(204) else: self._set_headers(404) # Encode the new animal and send in response self.wfile.write("".encode())
def do_PUT(self): content_len = int(self.headers.get('content-length', 0)) post_body = self.rfile.read(content_len) post_body = json.loads(post_body) # Parse the URL (resource, id) = self.parse_url(self.path) success = False if resource == "animals": success = update_animal(id, post_body) if resource == "customers": update_customer(id, post_body) if resource == "employees": update_employee(id, post_body) if resource == "locations": update_location(id, post_body) # rest of the elif's if success: self._set_headers(204) else: self._set_headers(404) self.wfile.write("".encode())
def do_PUT(self): self._set_headers(204) content_len = int(self.headers.get('content-length', 0)) post_body = self.rfile.read(content_len) # turns into post body when json loads post_body = json.loads(post_body) # Parse the URL (resource, id) = self.parse_url(self.path) # checks for resourse, passes id and post body if resource == "animals": update_animal(id, post_body) if resource == "customers": update_customer(id, post_body) if resource == "employees": update_employee(id, post_body) if resource == "locations": update_location(id, post_body) # Encode the new animal and send in response self.wfile.write("".encode())
def do_PUT(self): # You should be able to explain which HTTP method is used by the client to request that a resource's state should change. self._set_headers(204) content_len = int(self.headers.get('content-length', 0)) post_body = self.rfile.read(content_len) post_body = json.loads(post_body) # Parse the URL (resource, id) = self.parse_url(self.path) success = False if resource == "animals": success = update_animal(id, post_body) # Encode the new animal and send in response # self.wfile.write("".encode()) if resource == "customers": success = update_customer(id, post_body) # Encode the new customer and send in response # self.wfile.write("".encode()) if resource == "employees": success = update_employee(id, post_body) # Encode the new employee and send in response # self.wfile.write("".encode()) if resource == "locations": success = update_location(id, post_body) # Encode the new location and send in response if success: self._set_headers(204) else: self._set_headers(404) self.wfile.write("".encode())
def do_PUT(self): content_len = int(self.headers.get('content-length', 0)) post_body = self.rfile.read(content_len) post_body = json.loads(post_body) # Parse the URL (resource, id) = self.parse_url(self.path) print(resource) success = False # update single animal from list if resource == "animals": success = update_animal(id, post_body) elif resource == "customers": success = update_customer(id, post_body) elif resource == "employees": success = update_employee(id, post_body) elif resource == "locations": success = update_location(id, post_body) self.wfile.write("".encode())
def update_employee(): if request.method == "GET": id = request.args.get("id") restaurantID = request.args["restaurantID"] restaurant = restaurants.get_restaurant(restaurantID) employee = employees.get_employee(id) return render_template("update_employee.html", employee=employee, restaurant=restaurant) if request.method == "POST": id = request.form["id"] new_firstname = request.form["new_firstname"] new_lastname = request.form["new_lastname"] new_role = request.form["new_role"] new_max_hours = request.form["new_max_hours"] restaurantID = request.form["restaurantID"] if employees.update_employee(id, new_firstname, new_lastname, new_role, new_max_hours): flash("Työntekijän päivitys onnistui!") return redirect("/") else: return render_template("error.html", message="Työntekijän muokkaus epäonnistui")