def categories_add():
    category = models.category()
    form = forms.categories(request.form, category)
    form.id = category.id
    if request.method == 'POST':
        if form.validate_on_submit():
            category.position = category.get_position()
            g.mysql.add(form.get_instance(category))
            g.mysql.commit()
            flash('The category was saved successfully.', 'success')
            return redirect(url_for('administrators.categories_overview'))
        flash('The category was not saved successfully.', 'danger')
    return render_template('administrators/views/categories_add.html', form=form)
def categories_edit(id):
    category = g.mysql.query(models.category).get(id)
    if not category:
        abort(404)
    form = forms.categories(request.form, category)
    form.id = category.id
    if request.method == 'POST':
        if form.validate_on_submit():
            g.mysql.add(form.get_instance(category))
            g.mysql.commit()
            flash('The category was updated successfully.', 'success')
            return redirect(url_for('administrators.categories_overview'))
        flash('The category was not updated successfully.', 'danger')
    return render_template('administrators/views/categories_edit.html', form=form, id=id)