Beispiel #1
0
def delete_item(category_id, item_id):
    if request.method == 'POST':
        item = db_item(session, item_id)
        if item and is_logged_in_as_owner(login_session, item.user_id):
            db_delete_item(session, item)
            return redirect(
                url_for('show_items_in_category', category_id=category_id))
        else:
            # problem with item, try again
            return redirect(
                url_for('delete_item',
                        category_id=category_id,
                        item_id=item_id))
    else:
        category = db_category(session, category_id)
        item = db_item(session, item_id)
        if is_logged_in_as_owner(login_session, item):
            return render_template(
                'deleteitem.html',
                category=category,
                item=item,
                is_logged_in=is_already_logged_in(login_session))
        else:
            flash(
                "To delete an item, you must first be logged as the item's owner."
            )
            return redirect(url_for('showLogin'))
Beispiel #2
0
def edit_item(category_id, item_id):
    if request.method == 'POST':
        item_from_database = db_item(session, item_id)
        item_from_form = item_from_request_post(request)
        if item_from_form and is_logged_in_as_owner(
                login_session, item_from_database.user_id):
            item_from_database.name = item_from_form.name
            item_from_database.description = item_from_form.description

            session.commit()
            return redirect(
                url_for('show_items_in_category', category_id=category_id))
        else:
            # problem with item, try again
            return redirect(
                url_for('edit_item', category_id=category_id, item_id=item_id))
    else:
        category = db_category(session, category_id)
        item = db_item(session, item_id)
        if is_logged_in_as_owner(login_session, item):
            cancel_url = '/catalog/category/' + str(
                item.category_id) + '/item/' + str(item_id)
            return render_template(
                'edititem.html',
                category=category,
                item=item,
                cancel_url=cancel_url,
                is_logged_in=is_already_logged_in(login_session))
        else:
            flash(
                "To edit an item, you must first be logged in as the item's owner."
            )
            return redirect(url_for('showLogin'))
def delete_item(category_id, item_id):
    if request.method == 'POST':
        item = db_item(session, item_id)
        if item and is_logged_in_as_owner(login_session, item.user_id):
            db_delete_item(session, item)
            return redirect(url_for('show_items_in_category', category_id=category_id))
        else:
            # problem with item, try again
            return redirect(url_for('delete_item', category_id=category_id, item_id=item_id))
    else:
        category = db_category(session, category_id)
        item = db_item(session, item_id)
        if is_logged_in_as_owner(login_session, item):
            return render_template('deleteitem.html', category=category, item=item,
                                   is_logged_in=is_already_logged_in(login_session))
        else:
            flash("To delete an item, you must first be logged as the item's owner.")
            return redirect(url_for('showLogin'))
Beispiel #4
0
def show_item(category_id, item_id):
    category = db_category(session, category_id)
    item = db_item(session, item_id)
    return render_template('item.html',
                           category=category,
                           item=item,
                           is_logged_in=is_already_logged_in(login_session),
                           is_logged_in_owner=is_logged_in_as_owner(
                               login_session, item.user_id))
def edit_item(category_id, item_id):
    if request.method == 'POST':
        item_from_database = db_item(session, item_id)
        item_from_form = item_from_request_post(request)
        if item_from_form and is_logged_in_as_owner(login_session, item_from_database.user_id):
            item_from_database.name = item_from_form.name
            item_from_database.description = item_from_form.description

            session.commit()
            return redirect(url_for('show_items_in_category', category_id=category_id))
        else:
            # problem with item, try again
            return redirect(url_for('edit_item', category_id=category_id, item_id=item_id))
    else:
        category = db_category(session, category_id)
        item = db_item(session, item_id)
        if is_logged_in_as_owner(login_session, item):
            cancel_url = '/catalog/category/' + str(item.category_id) + '/item/' + str(item_id)
            return render_template('edititem.html', category=category, item=item, cancel_url=cancel_url,
                                   is_logged_in=is_already_logged_in(login_session))
        else:
            flash("To edit an item, you must first be logged in as the item's owner.")
            return redirect(url_for('showLogin'))
def show_item(category_id, item_id):
    category = db_category(session, category_id)
    item = db_item(session, item_id)
    return render_template('item.html', category=category, item=item,
                           is_logged_in=is_already_logged_in(login_session),
                           is_logged_in_owner=is_logged_in_as_owner(login_session, item.user_id))