Example #1
0
def tags():
    if request.method == 'GET':
        q = request.args.get('q')

        if q is None:
            result = Tag.get_tags(session)
        else:
            result = Tag.search_tags(session, q)

        j = []
        for t in result:
            j.append(t.to_json())

        return jsonify(AjaxResult(True, 'Tags retrieved successfully', j).to_json())

    if request.method == 'POST':
        result = Tag.create_tag(session, request.form['tagName'])

        if not result:
            return jsonify(AjaxResult(False, 'Tag already exists in database').to_json())
        else:
            return jsonify(AjaxResult(True, 'Tag created successfully').to_json())
Example #2
0
def tag(tag_id):
    t = Tag.get_tag(session, tag_id)
    return jsonify(AjaxResult(True, 'Tag retrieved successfully', t.to_json()).to_json())