Ejemplo n.º 1
0
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(),
    )
Ejemplo n.º 2
0
def listCategory():
    """A View containing the list of Categories.

    Returns:
        Presents the user with a list of all user Categories
    """
    categories = Category.query.all()

    return render_template(
        "generic.html",
        modelType="category",
        viewType=os.path.join("partials", "list.html"),
        objects=categories,
        client_id=CLIENT_ID,
        state=getLoginSessionState(),
    )
Ejemplo n.º 3
0
def listUser():
    """Present the Web User with an Edit View for the their User account.

    Returns:
        Presents the user with a list of all user Names
    """
    users = User.query.all()

    return render_template(
        "generic.html",
        modelType="user",
        viewType=os.path.join("partials", "list.html"),
        objects=users,
        client_id=CLIENT_ID,
        state=getLoginSessionState(),
    )
Ejemplo n.º 4
0
def listCategoryItem(category_name):
    """List all Items in a category.

    Args:
        category_name (string): The category of items to be viewed.

    Returns:
        A GET request presents the user with the list of all items belonging to
        the specified category.

    """
    # Find the category by its name, and all Items with that category's id.
    category = Category.query.filter_by(name=category_name).one()
    items = Item.query.filter_by(cat_id=category.id).all()

    # Present the List of Items 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(),
    )