Exemplo n.º 1
0
def show_item(category_id, item_id):
    """Specific item page. Shows desc."""
    categories = db.get_all_categories()
    cat = db.get_cat(category_id)
    item = db.get_item(item_id)
    return render_template('item.html',
                           categories=categories,
                           category=cat,
                           item=item)
Exemplo n.º 2
0
def show_item(category_id, item_id):
    """Specific item page. Shows desc."""
    categories = db.get_all_categories()
    cat = db.get_cat(category_id)
    item = db.get_item(item_id)
    return render_template(
        'item.html',
        categories=categories,
        category=cat,
        item=item
        )
Exemplo n.º 3
0
def edit_item(category_id, item_id):
    """Edit item page. User must have created the item to edit."""

    categories = db.get_all_categories()
    cat = db.get_cat(category_id)
    item = db.get_item(item_id)
    user_id = login_session['user_id']

    if item.user_id != user_id:
        return redirect(url_for('main_page'))

    if request.method == 'POST':
        name = request.form['name']
        description = request.form['description']
        category = request.form['category']

        field_vals = {}

        if name and description:
            flash('Item edited!')
            db.edit_item(item, name, description, db.get_cat_id(category))

            time.sleep(1)
            return redirect(url_for(
                'show_item',
                category_id=category_id,
                item_id=item_id
                )
            )
        else:
            field_vals['default_cat'] = category
            flash('Invalid input! Must enter values.')

        field_vals['input_name'] = name
        field_vals['input_description'] = description
        return render_template('new_item.html', categories=categories, **field_vals)
    else:
        return render_template(
            'edit_item.html',
            category_id=category_id,
            item_id=item_id,
            categories=categories,
            input_name=item.name,
            input_description=item.description,
            default_cat=cat.name
            )
Exemplo n.º 4
0
def edit_item(category_id, item_id):
    """Edit item page. User must have created the item to edit."""

    categories = db.get_all_categories()
    cat = db.get_cat(category_id)
    item = db.get_item(item_id)
    user_id = login_session['user_id']

    if item.user_id != user_id:
        return redirect(url_for('main_page'))

    if request.method == 'POST':
        name = request.form['name']
        description = request.form['description']
        category = request.form['category']

        field_vals = {}

        if name and description:
            flash('Item edited!')
            db.edit_item(item, name, description, db.get_cat_id(category))

            time.sleep(1)
            return redirect(
                url_for('show_item', category_id=category_id, item_id=item_id))
        else:
            field_vals['default_cat'] = category
            flash('Invalid input! Must enter values.')

        field_vals['input_name'] = name
        field_vals['input_description'] = description
        return render_template('new_item.html',
                               categories=categories,
                               **field_vals)
    else:
        return render_template('edit_item.html',
                               category_id=category_id,
                               item_id=item_id,
                               categories=categories,
                               input_name=item.name,
                               input_description=item.description,
                               default_cat=cat.name)
Exemplo n.º 5
0
def delete_item(category_id, item_id):
    """Delete item page.  User must have created item to delete."""

    cat = db.get_cat(category_id)
    item = db.get_item(item_id)

    user_id = login_session['user_id']

    if item.user_id != user_id:
        return redirect(url_for('main_page'))

    if request.method == 'POST':
        delete_confirmation = request.form['delete']

        if delete_confirmation == 'yes':
            db.delete_item(item)
            flash('Item entry deleted.')
        return redirect(url_for('show_category', category_id=cat.id))
    else:
        return render_template('delete_item.html', category=cat, item=item)
Exemplo n.º 6
0
def delete_item(category_id, item_id):
    """Delete item page.  User must have created item to delete."""

    cat = db.get_cat(category_id)
    item = db.get_item(item_id)

    user_id = login_session['user_id']

    if item.user_id != user_id:
        return redirect(url_for('main_page'))

    if request.method == 'POST':
        delete_confirmation = request.form['delete']

        if delete_confirmation == 'yes':
            db.delete_item(item)
            flash('Item entry deleted.')
        return redirect(url_for('show_category', category_id=cat.id))
    else:
        return render_template(
            'delete_item.html',
            category=cat,
            item=item
            )
Exemplo n.º 7
0
def item_json(category_id, item_id):
    item = db.get_item(item_id)
    return jsonify(Item=item.serialize)
Exemplo n.º 8
0
def item_json(category_id, item_id):
    item = db.get_item(item_id)
    return jsonify(Item=item.serialize)