def showUser(user_id, **kwargs):
    """
    Show the user page with user specific management options.
    """
    return render_template('user.html',
                           items=itemGet(user_id=user_id, **kwargs),
                           user=userGet(user_id, **kwargs))
Exemple #2
0
 def wrapper(*args, **kwargs):
     if 'item_id' in kwargs:
         item = itemGet(**kwargs)
         if not item:
             flash('Oops, but that item does not exist')
             return redirect(url_for('homepage'))
     return function(*args, **kwargs)
def editItem(item_id=None, **kwargs):
    """
    Allows the creator of an item to update it from the database
    """
    if 'item_id' in kwargs:
        item_id = kwargs['item_id']

    params = dict()
    has_error = False

    form_fields = [
        '*name',
        '*description',
        'meta_description',
        'price',
        '*tags',
        'category_id',
        'collection_id'
    ]

    user_id = session['user_id']
    if 'user_id' in kwargs:
        user_id = kwargs['user_id']

    if item_id:
        item = itemGet(item_id, **kwargs)
    else:
        item = Item()

    if request.method == 'POST':

        item, params, has_error = processFormFields(
            form_fields, item, params, has_error)

        if not has_error:
            if not item_id:
                item.seo_url=slugify(item.name)
                item.user_id=user_id

            coll = itemSet(item)

            if not item_id:
                item_id = next(iter(coll))

            if coll[item_id]:
                flash('Item Successfully Edited')
                print("updated item = %s" % coll[item_id])
                return redirect(url_for('showItem', item_id=item_id))
            else:
                flash('Item Update Failed!')
                params['error_submit'] = "Unable to update item"
                has_error = True

    return render_template(
        'edit_item.html',
        item=item,
        collections=collectionGet(user_id=user_id),
        categories=categoryGet(user_id=user_id),
        params=params)
Exemple #4
0
def homepage(*args, **kwargs):
    """
    Show all collections. This is the home page.
    """
    return render_template('homepage.html',
        items=itemGet(limit=app.config['PAGE_LIMIT']),
        title='Latest Items',
        view_title='View item'
    )
Exemple #5
0
def inject_menu():
    """
    Makes lists available to layout template for
    purpose of building the navigation menu links.
    """
    if isLoggedIn():
        return dict(menu_collections=collectionGet(limit=5),
                    menu_categories=categoryGet(limit=5),
                    menu_items=itemGet(limit=5),
                    messages=userItemCount())
    return dict()
def showItem(item_id, **kwargs):
    """
    Renders the page for a single item.

    Buttons for editing and deleting the item are also rendered for the
    item creator
    """
    return render_template(
        'item.html',
        item=itemGet(item_id, **kwargs),
        listview=request.args.get('listview'),
        params=dict()
    )
def showCategory(category_id, **kwargs):
    """
    Show all the items for the selected category.

    For the creator of the category, a button for editing and deleting
    the category is rendered.
    For the creator of an item, a button for editing and deleting the
    corresponding item is rendered.
    """
    return render_template('category.html',
                           items=itemGet(category_id=category_id, **kwargs),
                           category=categoryGet(category_id, **kwargs),
                           listview=request.args.get('listview'),
                           params=dict())
def deleteItem(item_id, **kwargs):
    """
    Deletes the selected item from the database
    """
    if request.method == 'POST':
        if itemDelete(item_id, **kwargs):
            flash('Item Successfully Deleted')
            return redirect(url_for('homepage', item_id=item_id))
            # TODO: this should be collection or somewhere else
        else:
            flash('Item NOT Deleted')
            item=itemGet(item_id, **kwargs)
            params = dict()
            params['error_deletion'] = "Unable to delete item"
            return render_template(
                'item.html',
                item=item,
                creator = userGet(item.user_id),
                params=params)
    else:
        return render_template(
            'delete_item.html',
            item=itemGet(item_id, **kwargs))
def showItems(**kwargs):
    """
    Show all the items.
    """
    creator = []
    if 'user_id' in kwargs:
        creator = userGet(kwargs['user_id'])

    items = itemGet(**kwargs)
    if 'json' in kwargs:
        return jsonify(Items=[i.serialize for i in items])

    return render_template(
        'items.html',
        items=items,
        listview=request.args.get('listview'),
        creator=creator,
        params=dict()
    )