Exemple #1
0
def tag_search(tag):
    form = TagsSearchForm(data={"tag": tag}, meta={"csrf": False})
    entities = {}
    tags = Project.get_top_with("tags")
    if form.validate():
        entities = Project.get_with_search("tags", form.tag.data)
    return render_template("projects/projects.html",
                           tags=list(tags.keys()),
                           objects=entities,
                           form=form)
Exemple #2
0
def tag_external_search():
    form = TagsSearchForm(request.args, meta={"csrf": False})
    entities = {}
    # The return form should contain a csrf_token
    return_form = TagsSearchForm()
    return_form.tag = form.tag
    if form.validate():
        entities = Project.get_with_search("tags", form.tag.data)
        return render_template("projects/projects.html",
                               objects=entities,
                               form=return_form)
    # pass on errors
    return_form._errors = form.errors
    return_form._fields["tag"] = form._fields["tag"]
    return render_template("projects/projects.html",
                           objects=entities,
                           form=return_form)
Exemple #3
0
def tag_native_search():
    form = TagsSearchForm(request.form)
    if form.validate_on_submit():
        result = {}
        tag = request.form["tag"]
        entities = Project.get_with_search("tags", tag)
        if len(entities) > 0:
            result = [entity.serialize() for entity in entities]
        return jsonify(data=result)

    response = jsonify(
        data={
            "danger":
            ", ".join([
                msg for attr, errors in form.errors.items() for msg in errors
            ])
        })
    response.status_code = 400
    return response