コード例 #1
0
def index_category_items(category_id):
    category = db.get_category(category_id)
    items = db.get_category_items(category_id)
    return render_template(
        'category_items/category_items.html',
        category=category,
        items=items)
コード例 #2
0
def delete_category(category_id):
    if request.method == 'POST':
        db.delete_category(category_id)
        flash("category deleted!")
        return redirect(url_for('index_categories'))
    else:
        category = db.get_category(category_id)
        if g.user.id != category.user_id:
            flash("You are not authorized to delete this category!")
            return redirect(url_for('index_categories'))
        return render_template('categories/delete_category.html',
                               category_id=category_id,
                               category=category)
コード例 #3
0
def edit_category(category_id):
    if request.method == 'POST':
        name = request.form['categoryname']
        description = request.form['categorydescription']
        image = request.form['categoryimage']
        if image == None or image == "":
            image = url_for('static', filename='img/music.jpg')

        db.edit_category(category_id, name, description, image)
        flash("category edited!")
        return redirect(url_for('index_categories'))
    else:
        category = db.get_category(category_id)
        if g.user.id != category.user_id:
            flash("You are not authorized to edit this category!")
            return redirect(url_for('index_categories'))
        return render_template('categories/edit_category.html',
                               category_id=category_id,
                               category=category)
コード例 #4
0
def add_new_category_item(category_id):
    if request.method == 'POST':
        title = request.form['itemtitle']
        image = request.form['itemimage']
        description = request.form['itemdescription']
        if image == None or image == "":
            image = url_for('static', filename='img/music.jpg')

        category_item_obj = {
            'title': title,
            'description': description,
            'image': image,
            'user_id': g.user.id
        }
        db.new_category_item(category_id, category_item_obj)
        flash("New category item created!")
        return redirect(
            url_for('index_category_items', category_id=category_id))
    else:
        category = db.get_category(category_id)
        return render_template('category_items/add_new_category_item.html',
                               category=category)
コード例 #5
0
def get_category(category_id):
    category = db.get_category(category_id)
    return jsonify(Categories=category.serialize)