def item(item_id):
    """Returns the Item detail page.

    :param item_id: database id of the requested item.
    """
    item_object = catalog.get_item(item_id)
    return flask.render_template("item.html", item=item_object)
def item_delete(item_id):
    """Returns the page to delete the given item.

    :param item_id: database id of the requested item.
    """
    form = item_forms.ItemDeleteForm()
    item_object = catalog.get_item(item_id)
    if form.validate_on_submit():
        catalog.delete_item(item_object.id)
        return root({"success": "Item deleted successfully!"})
    return flask.render_template("item_delete.html", form=form, item=item_object)
def item_edit(item_id):
    """Returns a page to edit the given item.

    :param item_id: database id of the requested item.
    """
    form = item_forms.ItemEditForm()
    form.category.choices = [(x.id, x.name) for x in catalog.get_all_categories()]
    item_object = catalog.get_item(item_id)
    if form.validate_on_submit():
        catalog.update_item(item_object.id, form.name.data, form.category.data, form.description.data)
        return root({"success": "Item updated successfully!"})
    form.name.data = item_object.name
    form.category.data = item_object.category
    form.description.data = item_object.description
    return flask.render_template("item_edit.html", form=form, item=item_object)