コード例 #1
0
ファイル: views.py プロジェクト: frost-byte/catalog
def listItem():
    """List all Items in the catalog.

    Returns:
        A GET request presents the user with the list of all catalog items.

    """
    # Retrieve the list of items and order them by their creation date.
    # Starting with the newest and ending with the oldest.
    items = Item.query.order_by(desc(Item.dateCreated)).all()

    # Generate a list of ( Category Name, Item Name) tuples?
    # This lets the view display each item with its respective category
    results = [(Category.findByID(i.cat_id).name, i.name) for i in items]
    objects = []

    # Convert the list to contain a dictionary for each item/category combo.
    for category, item in results:
        objects.append({"category": category, "item": item})

    # Present the list of all items and their categories in the main view.
    return render_template(
        "generic.html",
        viewType=os.path.join("partials", "list.html"),
        modelType="item",
        objects=items,
        client_id=CLIENT_ID,
        state=getLoginSessionState(),
    )