Ejemplo n.º 1
0
def category_delete_route(category_name):
    """
    Deleting category from DB
    """
    target_category = get_category(category_name)

    # checking access rights
    if target_category.owner != user_info()['id']:
        flash('Only owner can delete category')
        return redirect(url_for('categories_route'))

    if target_category is None:
        abort(404)

    if request.method == 'POST':
        delete_category(category_name)
        flash('Category deleted')
        # sending user to list of categories after all he has done
        return redirect(url_for('categories_route'))

    # as polite people we will ask some configmation first,
    # also we need it for CSRF check
    if request.method == 'GET':
        return render_template('confirm.html',
                               page={'title': 'Delete category'},
                               user=user_info(),
                               content={
                                   'message':
                                   'Do you really want delete category ' +
                                   target_category.name + '?'
                               })
Ejemplo n.º 2
0
def category_edit_route(category_name):
    """
    Updating category info
    """
    target_category = get_category(category_name)

    # checking access rights
    if target_category.owner != user_info()['id']:
        flash('Only owner can edit category')
        return redirect(url_for('categories_route'))

    if target_category is None:
        abort(404)

    if request.method == 'POST':
        update_category(category_name)
        flash('Category updated')
        return redirect(url_for('categories_route'))

    if request.method == 'GET':
        return render_template('category_edit.html',
                               page={'title': 'Add category'},
                               user=user_info(),
                               content={
                                   'is_edit': True,
                                   'category': target_category
                               })
Ejemplo n.º 3
0
def category_route(category_name):
    """
    Outputing category info
    """
    target_category = get_category(category_name)
    print target_category

    # ooops category not found
    if target_category is None:
        abort(404)

    return render_template('category.html',
                           page={
                               'title': 'Category ' + target_category.name,
                               'has_sidebar': True
                           },
                           user=user_info(),
                           content={
                               'categories': get_categories(),
                               'category': target_category
                           })
Ejemplo n.º 4
0
def item_add_route(category_name):
    """
    Route to add new item
    """
    target_category = get_category(category_name)

    if target_category is None:
        abort(404)

    if request.method == 'POST':

        add_item(target_category.name)
        flash('Item added')
        return redirect(url_for('category_route', category_name=category_name))

    if request.method == 'GET':
        return render_template('item_edit.html',
                               page={'title': 'Add category'},
                               user=user_info(),
                               content={
                                   'is_edit': False,
                                   'category': target_category
                               })