예제 #1
0
def edit_category(id):

    form = CategoryForm.AddForm()
    if form.validate_on_submit():
        category = Category()
        if (category.is_exist(id) != True):
            flash('Sorry,That category doesn\'t exist',
                  category='errorMessage')
            return redirect(redirect_back())
        if category.exist_twice(request.form['name']):
            flash('Sorry,There is another category with the same name',
                  category='errorMessage')
            return redirect(redirect_back())
        save_category = category.update(request.form['name'], id)
        if (save_category):
            flash(' Category \'{0}\' has been successfully updated'.format(
                category.name),
                  category='successMessage')
            return redirect(redirect_back())
        flash('Unable to save category', category='errorMessage')
        flash(request.form, category='input')
        return redirect(redirect_back())
    error = form.errors
    flash(error, category='error')
    flash(request.form, category='input')
    return redirect(redirect_back())
예제 #2
0
def delete_category(id):
    category = Category()
    if (category.is_exist(id) != True):
        flash('Sorry,That category doesn\'t exist', category='errorMessage')
        return redirect(redirect_back())
    delete_category = category.delete(id)
    if (delete_category):
        flash(' Category has been successfully deleted',
              category='successMessage')
        return redirect(redirect_back())
    flash('Unable to save category', category='errorMessage')
    flash(request.form, category='input')
    return redirect(redirect_back())