Пример #1
0
def category_info(category_id):
    """
    Function to return a page to view items for specified category.

    Args:
        category_id: ID value of the category to view.
    """

    set_redirect_url()

    # Retrieve Category object for template rendering.
    # If not found, render error template.
    category = db_session.query(Category)\
        .filter_by(id=category_id)\
        .first()
    if not category:
        return render_template(
            'error.html',
            headline_text='Category Not Found',
            error_text='The specified category was not found.')

    login_session['last_category_id'] = category.id
    category_items = db_session.query(CategoryItem).filter_by(
        category_id=category.id).all()
    creator = category.user
    user = get_user()

    return render_template('category_info.html',
                           categories=get_all_objects_of_type(Category),
                           category=category,
                           category_items=category_items,
                           creator=creator,
                           items=get_all_items(),
                           user=user)
Пример #2
0
def index():
    """
    Function to return a page listing all categories and most recent items.
    """

    set_redirect_url()

    show_all = True if request.method == 'GET' and\
        str(request.args.get('show_all', False)).lower() == 'true'\
        else False
    categories = get_all_objects_of_type(Category)
    if not show_all:
        latest_items = get_last_x_items_of_type(10, CategoryItem)
        num_items = latest_items.count()
    else:
        latest_items = get_all_objects_of_type(CategoryItem)
        latest_items.reverse()
        num_items = len(latest_items)
    user = get_user()
    items = get_all_items()

    return render_template('home.html',
                           show_all=show_all,
                           categories=categories,
                           items=items,
                           latest_items=latest_items,
                           num_items=num_items,
                           user=user)
Пример #3
0
def category_item_info(item_id):
    """
    Function to return a page to view a category item.

    Args:
        item_id: ID value of the category item to view.
    """

    set_redirect_url()

    # Retrieve CategoryItem object for template rendering.
    # If not found, render error template.
    category_item = db_session.query(CategoryItem)\
        .filter_by(id=item_id)\
        .first()
    if not category_item:
        return render_template('error.html',
                               headline_text='Item Not Found',
                               error_text='The specified item was not found.')

    creator = category_item.user
    user = get_user()

    return render_template('category_item_info.html',
                           categories=get_all_objects_of_type(Category),
                           category=category_item.category,
                           item=category_item,
                           items=get_all_items(),
                           creator=creator,
                           user=user)
Пример #4
0
def category_info(category_id):
    """
    Function to return a page to view items for specified category.

    Args:
        category_id: ID value of the category to view.
    """

    set_redirect_url()

    # Retrieve Category object for template rendering.
    # If not found, render error template.
    category = db_session.query(Category)\
        .filter_by(id=category_id)\
        .first()
    if not category:
        return render_template('error.html',
                               headline_text='Category Not Found',
                               error_text='The specified category was not found.')

    login_session['last_category_id'] = category.id
    category_items = db_session.query(CategoryItem).filter_by(category_id=category.id).all()
    creator = category.user
    user = get_user()

    return render_template('category_info.html',
                           categories=get_all_objects_of_type(Category),
                           category=category,
                           category_items=category_items,
                           creator=creator,
                           items=get_all_items(),
                           user=user)
Пример #5
0
def index():
    """
    Function to return a page listing all categories and most recent items.
    """

    set_redirect_url()

    show_all = True if request.method == 'GET' and\
        str(request.args.get('show_all', False)).lower() == 'true'\
        else False
    categories = get_all_objects_of_type(Category)
    if not show_all:
        latest_items = get_last_x_items_of_type(10, CategoryItem)
        num_items = latest_items.count()
    else:
        latest_items = get_all_objects_of_type(CategoryItem)
        latest_items.reverse()
        num_items = len(latest_items)
    user = get_user()
    items = get_all_items()

    return render_template('home.html',
                           show_all=show_all,
                           categories=categories,
                           items=items,
                           latest_items=latest_items,
                           num_items=num_items,
                           user=user)
Пример #6
0
def category_item_info(item_id):
    """
    Function to return a page to view a category item.

    Args:
        item_id: ID value of the category item to view.
    """

    set_redirect_url()

    # Retrieve CategoryItem object for template rendering.
    # If not found, render error template.
    category_item = db_session.query(CategoryItem)\
        .filter_by(id=item_id)\
        .first()
    if not category_item:
        return render_template('error.html',
                               headline_text='Item Not Found',
                               error_text='The specified item was not found.')

    creator = category_item.user
    user = get_user()

    return render_template('category_item_info.html',
                           categories=get_all_objects_of_type(Category),
                           category=category_item.category,
                           item=category_item,
                           items=get_all_items(),
                           creator=creator,
                           user=user)