Browse Source

amélioration page dico

master
Astequ 1 year ago
parent
commit
04f9bb742f
6 changed files with 158 additions and 21 deletions
  1. +50
    -18
      app/__init__.py
  2. +4
    -0
      clivage.py
  3. +3
    -0
      static/home.css
  4. +70
    -0
      static/results.css
  5. +3
    -2
      templates/pages/home.html
  6. +28
    -1
      templates/pages/results.html

+ 50
- 18
app/__init__.py View File

@@ -1,3 +1,5 @@
from string import ascii_lowercase

from flask import Flask, abort, redirect, url_for, render_template
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
@@ -65,17 +67,14 @@ def vote_from_all(id: int, word: str):
@app.route('/vote/<int:id>/<string:word>/<string:vote>')
@app.route('/vote/<int:id>/<string:word>/<string:vote>/')
def vote_for(vote: str, id: int, word: str):
print(word)
db_word = db.session.query(Word).filter_by(id=id, text=word).scalar()

if db_word is None:
abort(404)

if Locale.is_left(vote):
print("left")
db_word.left = Word.left + 1
elif Locale.is_right(vote):
print("right")
db_word.right = Word.right + 1
else:
abort(400)
@@ -86,24 +85,57 @@ def vote_for(vote: str, id: int, word: str):

@app.route('/results')
@app.route('/results/')
@app.route('/results/<string:sort>')
@app.route('/results/<string:sort>/')
def results_index(sort: str = "id"):
if sort == "left":
def sort_key(x):
return x.left_percentage
elif sort == "right":
def sort_key(x):
return x.right_percentage
else:
def sort_key(x):
return x.word
@app.route('/results/<string:filter>')
@app.route('/results/<string:filter>/')
@app.route('/results/<int:nb>')
@app.route('/results/<int:nb>/')
@app.route('/results/<int:offset>/<int:nb>')
@app.route('/results/<int:offset>/<int:nb>/')
@app.route('/results/<int:nb>/<string:filter>')
@app.route('/results/<int:nb>/<string:filter>/')
@app.route('/results/<int:offset>/<int:nb>/<string:filter>')
@app.route('/results/<int:offset>/<int:nb>/<string:filter>/')
def results_index(nb=100, offset=0, filter=""):
offset = abs(offset)
nb = min(100, abs(nb))
if not not filter:
if filter.lower() not in ascii_lowercase:
filter = ""

link_prev = url_for("results_index", nb=nb, offset=max(offset - nb, 0), filter=filter) if filter else url_for(
"results_index", nb=nb, offset=max(offset - nb, 0))
link_next = url_for("results_index", nb=nb, offset=offset + nb, filter=filter) if filter else url_for(
"results_index", nb=nb, offset=offset + nb)

results = [
WordResult(result.text, result.left, result.right, url_for('vote_from_all', id=result.id, word=result.text)) for
result in
db.session.query(Word).from_statement(text("SELECT * FROM word WHERE word.right <> 0 OR word.left <> 0"))]
results.sort(key=sort_key, reverse=True)
return render_template("pages/results.html", color=UIColor.color_random(), results=results)
db.session.query(Word).from_statement(text(
"SELECT * FROM word WHERE (word.right <> 0 OR word.left <> 0) AND (word.text LIKE '{0}%' OR word.text LIKE '{1}%') LIMIT {2},{3}".format(
filter.lower(), filter.upper(), str(offset), str(nb))))]
return render_template("pages/results.html", color=UIColor.color_random(), results=results, next=link_next,
prev=link_prev, letters=ascii_lowercase, min_result=offset, max_result=offset + nb,
filter=filter)


# @app.route('/results/s/<string:sort>')
# @app.route('/results/s/<string:sort>/')
# def results_sorted(sort: str = "id"):
# if sort == "left":
# def sort_key(x):
# return 100 - x.right_percentage
# elif sort == "right":
# def sort_key(x):
# return 100 - x.left_percentage
# else:
# def sort_key(x):
# return x.word
# results = [
# WordResult(result.text, result.left, result.right, url_for('vote_from_all', id=result.id, word=result.text)) for
# result in
# db.session.query(Word).from_statement(text("SELECT * FROM word WHERE word.right <> 0 OR word.left <> 0"))]
# results.sort(key=sort_key)
# return render_template("pages/results.html", color=UIColor.color_random(), results=results)


if __name__ == '__main__':


+ 4
- 0
clivage.py View File

@@ -0,0 +1,4 @@
from app import app as application

if __name__ == "__main__":
application.run()

+ 3
- 0
static/home.css View File

@@ -0,0 +1,3 @@
#vote {
border-right: 1px solid rgba(255, 255, 255, 0.2);
}

+ 70
- 0
static/results.css View File

@@ -58,4 +58,74 @@ td {

.right:hover {
background-color: #104a79;
}

#letters {
grid-column: 2;
display: inline-flex;
justify-content: space-evenly;
align-content: center;
width: 100%;
flex-wrap: wrap;
}

#prev, #next {
text-align: center;
}

#prev {
grid-column: 1;
}

#next {
grid-column: 3;
}

nav > div {
grid-row: 1;
}

nav a {
background-color: rgba(0, 0, 0, 0.7);
display: block;
text-decoration: none;
color: #fff;
min-width: 1.5rem;
height: 1.5rem;
font-size: 1rem;
line-height: 1.5rem;
text-align: center;
border-radius: 1rem;
}

#letters > div:first-child > a {
padding-right: 0.5rem;
padding-left: 0.5rem;
}

#letters > div {
padding-left: 0.25rem;
padding-right: 0.25rem;
}

nav {
padding-top: 1rem;
display: grid;
grid-template-columns: 2rem auto 2rem;
grid-template-rows: auto;
width: 100%;
font-weight: bold;
}

h2, h3 {
margin: 0;
}

h2 {
font-size: 2.3rem;
}

h3 {
font-size: 1.5rem;
padding-left: 2rem;
}

+ 3
- 2
templates/pages/home.html View File

@@ -2,6 +2,7 @@

{% block link %}
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='vote.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='home.css') }}">
{% endblock %}

{% block style %}
@@ -17,8 +18,8 @@
<h1>Le fantastique jeu du clivage</h1>
<h2>Déterminer le bord politique de mots ou expressions</h2>
<div class="controls">
<a href="{{ url_for('vote_index') }}">Catégoriser des mots</a>
<a href="{{ url_for('results_index') }}">Consulter le dictionnaire</a>
<a id="vote" href="{{ url_for('vote_index') }}">Catégoriser des mots</a>
<a id="results" href="{{ url_for('results_index') }}">Consulter le dictionnaire</a>
</div>
</section>
{% endblock %}

+ 28
- 1
templates/pages/results.html View File

@@ -17,7 +17,34 @@
{% endblock %}

{% block content %}
<h1> Mots ayant reçu des votes </h1>
<nav>
<div id="prev"><a href="{{ prev }}"><</a></div>
<div id="letters">
<div><a href="{{ url_for("results_index") }}">Aucun</a></div>
{% for letter in letters %}
<div><a href="{{ url_for("results_index", filter=letter) }}">{{ letter | upper }}</a></div>
{% endfor %}
</div>
<div id="next"><a href="{{ next }}">></a></div>
</nav>
<h2>
Mots
{% if filter %}
commençant par {{ filter | upper }}
{% endif %}
ayant reçu des votes
({{ min_result }}-{{ max_result }})
</h2>
<h3>
{% if results | length == 0 %}
Aucun résultat
{% elif results | length == 1 %}
1 résultat
{% else %}
{{ results | length }} résultats
{% endif %}

</h3>
{% if results %}
<table>
{% if results | length > 0 %}


Loading…
Cancel
Save