mirror of https://github.com/MISP/PyTaxonomies
Improve search form
parent
1668b87df8
commit
aec809fac8
|
@ -1,3 +1,4 @@
|
|||
flask
|
||||
flask_bootstrap
|
||||
flask_nav
|
||||
flask_wtf
|
||||
|
|
|
@ -5,6 +5,9 @@ from flask import Flask, request, render_template
|
|||
from flask_bootstrap import Bootstrap
|
||||
from flask_nav import Nav
|
||||
from flask_nav.elements import Navbar, View
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField
|
||||
from wtforms.validators import DataRequired
|
||||
from pytaxonomies import Taxonomies
|
||||
|
||||
|
||||
|
@ -20,6 +23,7 @@ def mynavbar():
|
|||
)
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = '<changeme>'
|
||||
Bootstrap(app)
|
||||
app.config['BOOTSTRAP_SERVE_LOCAL'] = True
|
||||
app.debug = True
|
||||
|
@ -28,6 +32,11 @@ nav.init_app(app)
|
|||
#t = Taxonomies(manifest_path="../../misp-taxonomies/MANIFEST.json")
|
||||
t = Taxonomies()
|
||||
|
||||
|
||||
class SearchForm(FlaskForm):
|
||||
query = StringField('Query', validators=[DataRequired()])
|
||||
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
def index():
|
||||
return taxonomies()
|
||||
|
@ -43,15 +52,16 @@ def taxonomies(name=None):
|
|||
|
||||
@app.route('/search', methods=['GET', 'POST'])
|
||||
def search():
|
||||
if request.form.get('query'):
|
||||
form = SearchForm()
|
||||
if form.validate_on_submit():
|
||||
q = request.form.get('query')
|
||||
entries = t.search(q)
|
||||
if entries:
|
||||
to_display = {e: t.revert_machinetag(e) for e in entries}
|
||||
return render_template('search.html', query=q, entries=to_display)
|
||||
return render_template('search.html', form=form, entries=to_display)
|
||||
else:
|
||||
return render_template('search.html', query=q, entries=None)
|
||||
return render_template('search.html', query=None, entries=None)
|
||||
return render_template('search.html', form=form, entries=None)
|
||||
return render_template('search.html', form=form, entries=None)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{% extends "bootstrap/base.html" %}
|
||||
{% import "bootstrap/wtf.html" as wtf %}
|
||||
|
||||
{% block scripts %}
|
||||
{{ super() }}
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
<div class="container">
|
||||
<h1>Search {% if query %} - {{query}} {%endif%}</h1>
|
||||
|
||||
<form class="form-inline" role="form" action="search" method=post>
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" name="query" id=query placeholder="Search a thing ">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Search</button>
|
||||
<form class="form-inline" action="search" method=post>
|
||||
{{ form.csrf_token }}
|
||||
{{ form.query(size=20) }}
|
||||
<input type="submit" value="Search">
|
||||
</form>
|
||||
</br>
|
||||
<div>
|
||||
|
@ -39,12 +38,12 @@
|
|||
<td>
|
||||
{% if val|length == 3 %}
|
||||
{% if val[2].description %}
|
||||
{{ val[2].description.decode() }}
|
||||
{{ val[2].description }}
|
||||
{% elif val[2].expanded %}
|
||||
{{ val[2].expanded.decode() }}
|
||||
{{ val[2].expanded }}
|
||||
{%endif%}
|
||||
{% elif val[1].description %}
|
||||
{{ val[1].description.decode() }}
|
||||
{{ val[1].description }}
|
||||
{% else %}
|
||||
{{ val[1].predicate }}
|
||||
{%endif%}
|
||||
|
|
Loading…
Reference in New Issue