Exemple #1
0
def get_cataegory_listings(db_category_name, page):
    """
     creates a catalog template for a specific category
    Arguments:
        page: the page number of the list.
        db_category_name: the name of the category
    """

    parent_categories = catalogDb.get_all_parent_categories()
    sub_categories = catalogDb.get_all_sub_categories()
    latest_items = enumerate(catalogDb.get_latest_items(CUT_OFF_DATE,
                                                        NO_LATEST_ITEMS))

    all_items = catalogDb.get_items_by_category(db_category_name)
    pagination = cusotmPaginator(page, PER_PAGE_ITEMS, all_items)
    slices = enumerate(pagination.getPageSlice())
    if not latest_items:
        flash("Could not find anything for this category ", category="info")
    template = render_template("items_catalog.html",
                               parent_categories=parent_categories,
                               sub_categories=sub_categories,
                               latest_items=latest_items,
                               item_count=NO_LATEST_ITEMS,
                               all_items=slices)
    template += render_template("pages_list.html",
                                pagination=pagination)
    return template
Exemple #2
0
def get_user_list(page):
    """
    gets the list of user, paginates and
    creates a template for display
    Arguments:
        page: the page number of the list.
    """
    users = catalogDb.get_all_user()
    # if records found list all record
    if(len(users) >= 1):
        pagination = cusotmPaginator(page, PER_PAGE_ITEMS, users)
        slices = pagination.getPageSlice()
        resultsTemplate = render_template(
            "users_list.html", users=slices,
            SESSION=login_session, pagination=pagination)
        resultsTemplate += render_template("pages_list.html",
                                           pagination=pagination)
    else:
        resultsTemplate = render_template("empty_list.html")
    return resultsTemplate
Exemple #3
0
def get_catalog(page):
    """
     creates a catalog template for display
    Arguments:
        page: the page number of the list.
    """
    parent_categories = catalogDb.get_all_parent_categories()
    sub_categories = catalogDb.get_all_sub_categories()
    latest_items = enumerate(catalogDb.get_latest_items(CUT_OFF_DATE,
                                                        NO_LATEST_ITEMS))
    all_items = catalogDb.get_all_items(True)
    pagination = cusotmPaginator(page, PER_PAGE_ITEMS, all_items)
    slices = enumerate(pagination.getPageSlice())
    template = render_template("items_catalog.html",
                               parent_categories=parent_categories,
                               sub_categories=sub_categories,
                               latest_items=latest_items,
                               item_count=NO_LATEST_ITEMS,
                               all_items=slices)
    template += render_template("pages_list.html",
                                pagination=pagination)
    return template
Exemple #4
0
def get_item_list(page):
    """
    gets the list of items for a user, paginates and
    creates a template for display
    Arguments:
        page: the page number of the list.
    """
    # check if admin is logged in if yes fetch all items
    if is_admin_loggedin():
        items = catalogDb.get_all_items()
    elif is_someone_Loggedin():
        # check if someone is logged in if yes fetch all items
        # for that user only
        app.logger.debug(
            "Fetching records for user " + str(login_session['userid']))
        items = catalogDb.get_all_items_user(login_session['userid'])
        app.logger.debug(str(len(items)) + " records found")
        if len(items) == 0:
            # if no records found list all records in read only mode
            app.logger.debug("Getting all records found")
            flash("You have not added any Items yet", category="warning")
            items = catalogDb.get_all_items()
    else:
        # list all records in read only mode
        items = catalogDb.get_all_items()

    if len(items) >= 1:
        # if more than one record then paginate
        pagination = cusotmPaginator(page, PER_PAGE_ITEMS, items)
        slices = pagination.getPageSlice()
        output = render_template(
            "items_list.html", items=slices, SESSION=login_session,
            pagination=pagination)
        output += render_template("pages_list.html",
                                  pagination=pagination)
    else:
        output = render_template('error.html',
                                 message="You Have not added any Items yet")
    return output
Exemple #5
0
def get_categories_list(page):
    """
    returns the category list template
    Arguments:
        page: the page number of the list.
    """
    resultsTemplate = ""
    categories = catalogDb.get_all_categories()
    # Check if there are categories
    if(len(categories) >= 1):
        pagination = cusotmPaginator(page, PER_PAGE_ITEMS, categories)
        slices = pagination.getPageSlice()
        resultsTemplate = render_template(
            "category_list.html", categories=slices,
            SESSION=login_session, pagination=pagination)
        resultsTemplate += render_template("pages_list.html",
                                           pagination=pagination)
    else:
        # if categories not found return the user to error page
        resultsTemplate = render_template(
            "error.html",
            message="Sorry we could not find what you were looking for")
    return resultsTemplate