Esempio n. 1
0
def add_role(name):
    """ Add New Post Category """
    try:
        c = Category()
        c.name = name
        c.set_slug(name)
        c.description = 'Default Description'
        c.save()
    except Exception as exp:
        print(exp)
    else:
        print(c.__repr__())
        del c
Esempio n. 2
0
def add_category():
    form = CategoryForm()
    if form.validate_on_submit():
        content = request.get_json()
        if content is not None:
            category = Category()
            category.name = content['name']
            category.description = content['description']
            category.set_slug(content['name'])
            category.save()
            category_id = str(category.id)
            return make_response(jsonify({'Success': category_id}))
        else:
            return make_response(jsonify({'Err': 'Request Content None'}))
    else:
        return make_response(jsonify({'Err': form.errors}))