add plain text form

develop
gwen 2 years ago
parent c156577470
commit c1b57c13f7

@ -39,7 +39,42 @@ def home():
"""home route""" """home route"""
if request.method == 'POST': if request.method == 'POST':
search = request.form['search'] search = request.form['search']
return render_template("form2.html", search=search) #actecol.find({key: { $regex: new RegExp(search, 'i')}})
query = [
{
"$match": {
"xmlcontent": {
"$regex": search,
"$options" :'i' # case-insensitive
}
}
},
{
'$group': {'_id': {'prince_name': '$prince_name',
'house': '$house',
'date': '$date',
'prince_code': '$prince_code',
'filename': '$filename',
"place": "$place.name",
"diplo_state": "$diplo_state",
"diplo_type": "$diplo_type"
}
}
}]
results = list(actecol.aggregate(query))
transformed_query = [pr['_id'] for pr in results]
invert_prince_bigram = {val: key for key, val in prince_bigram.items()}
# constructing the dateitem
for trs in transformed_query:
trs['house'] = trs['house'].capitalize()
trs['dateitem'] = make_timeitem_from_filename(trs['filename'])
bigram, number = trs['prince_code'].split('_')
long_prince_bigram = inverted_prince_bigram(bigram) + '_' + number
trs['prince_url'] = prince_name=long_prince_bigram.capitalize()
return render_template("plainsearch.html", search=search, actes=transformed_query)
return render_template("home.html") return render_template("home.html")
@ -77,7 +112,7 @@ def actes(house):
# [('Agnès de Bourgogne', 'agn_i'), ('Anne Dauphine', 'ann_i'), ('Charles Ier de Bourbon', 'ch_i'), ('Louis II de Bourbon', 'lo_ii') # [('Agnès de Bourgogne', 'agn_i'), ('Anne Dauphine', 'ann_i'), ('Charles Ier de Bourbon', 'ch_i'), ('Louis II de Bourbon', 'lo_ii')
princes = princes_in_houses[house] princes = princes_in_houses[house]
# TODO : modify the jinja template's design in order to suppress this ugly line # TODO : modify the html template's design in order to suppress this ugly line
princes = [(prc['prince_name'], prc['prince_code']) for prc in princes] princes = [(prc['prince_name'], prc['prince_code']) for prc in princes]
return render_template("corpus.html", house=house.capitalize(), princes=princes) return render_template("corpus.html", house=house.capitalize(), princes=princes)
@ -106,7 +141,6 @@ def prince_corpus(house=None, prince=None):
"date_time": "$date_time", "date_time": "$date_time",
"analysis": '$analysis', "analysis": '$analysis',
"place": "$place.name", "place": "$place.name",
#"ref_acte": "$ref_acte"
"diplo_state": "$diplo_state", "diplo_state": "$diplo_state",
"diplo_type": "$diplo_type" "diplo_type": "$diplo_type"
} }
@ -115,7 +149,6 @@ def prince_corpus(house=None, prince=None):
])) ]))
transformed_query = [pr['_id'] for pr in query] transformed_query = [pr['_id'] for pr in query]
invert_prince_bigram = {val: key for key, val in prince_bigram.items()} invert_prince_bigram = {val: key for key, val in prince_bigram.items()}
#print(invert_prince_bigram)
# constructing the dateitem # constructing the dateitem
for trs in transformed_query: for trs in transformed_query:
@ -123,7 +156,6 @@ def prince_corpus(house=None, prince=None):
bigram, number = trs['prince_code'].split('_') bigram, number = trs['prince_code'].split('_')
long_prince_bigram = inverted_prince_bigram(bigram) + '_' + number long_prince_bigram = inverted_prince_bigram(bigram) + '_' + number
return render_template("prince_corpus.html", house=house, duke_name=prince_long_name, return render_template("prince_corpus.html", house=house, duke_name=prince_long_name,
prince_name=long_prince_bigram.capitalize(), actes=transformed_query) prince_name=long_prince_bigram.capitalize(), actes=transformed_query)

@ -1,43 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
a {
text-decoration: none;
display: inline-block;
padding: 8px 16px;
}
a:hover {
background-color: #ddd;
color: black;
}
.previous {
background-color: #f1f1f1;
color: black;
}
.next {
background-color: #04AA6D;
color: white;
}
.round {
border-radius: 50%;
}
</style>
</head>
<body>
<h2>En travaux</h2>
<p>Résulat du query : {{ search }} </p>
<a onclick="history.back()" class="next">&laquo; Retour</a>
</body>
</html>

@ -0,0 +1,34 @@
{% extends "container.html" %}
{% block corps %}
<div class="container marketing" style="margin-top: 50px;">
<div>
<h1>Résulat de la recherche</h1>
<h2>Résulat de la recherche sur "<b>{{ search }}</b>" : </h2>
{% for acte in actes %}
<div>
<div class="title-princier">
<h3></h3>
</div>
<div class="pboly">
<p class="chrono-p font-weight-bold"><a href="{{url_for('main.acte', house=acte['house'], prince=acte['prince_url'], dateitem=acte['dateitem'])}}">{{ acte['prince_name'] }}, {{ acte['date'] }}.</a></p>
<p style="margin-bottom: 5%">
{% if acte['place'] != 'NS' %}
<span class="badge badge-pill badge" style="background-color: #284AA7; color: white; font-size: small;">{{ acte['place'] }}</span>
{% endif %}
<span class="badge badge-pill badge" style="background-color: #A7288A; color: white; font-size: small;">{{ acte['diplo_state'] }}</span>
<span class="badge badge-pill badge" style="background-color: #A78528; color: white; font-size: small;">{{ acte['diplo_type'] }}</span>
</p>
</div>
</div>
{% endfor %}
<a class="btn btn-outline-success my-2 my-sm-0" onclick="history.back()" >&laquo; Retour</a>
</div>
</div><!-- /.container -->
{% endblock %}
Loading…
Cancel
Save