Commit 50377553 authored by Nicolas Joyard's avatar Nicolas Joyard

Ajout page 'mes actions'

parent afd53c42
......@@ -69,12 +69,38 @@ def setup(app):
},
]
if session.get('user'):
acts = Action.query \
.filter(Parlementaire.id == Action.parlementaire_id) \
.filter(Action.etape == ETAPE_A_CONFIRMER) \
.filter(Action.user_id == session['user']['id']) \
.exists()
nb = Parlementaire.query.filter(acts) \
.filter(Parlementaire.etape ==
ETAPE_A_CONFIRMER) \
.count()
label = 'Mes actions'
if nb > 0:
title = '%s envoi%s à confirmer' % (nb, 's' if nb > 1 else '')
label += ' <span class="badge" data-toggle="tooltip" ' \
'title="%s">%s</span>' % (title, nb)
menu += [
{
'url': url_for('mes_actions'),
'label': '%s' % label,
'endpoint': 'mes_actions'
}
]
if session.get('user') and session.get('user')['admin']:
menu += [
{
'url': url_for('admin_recent'),
'label': '<span class="admin">Actions récentes</span>',
'endpoint': 'admin_recent"'
'endpoint': 'admin_recent'
}
]
......@@ -87,7 +113,7 @@ def setup(app):
'url': url_for('admin_en_attente'),
'label': '<span class="admin">À confirmer (%s)</span>'
% nb_aconfirmer,
'endpoint': 'admin_en_attente"'
'endpoint': 'admin_en_attente'
}
]
......
......@@ -8,12 +8,12 @@ from flask import (flash, redirect, render_template, request, session, url_for)
from flask_mail import Mail, Message
from sqlalchemy.orm import joinedload
from sqlalchemy.sql.expression import case, func
from sqlalchemy.sql.expression import func
from ..models import Action, Parlementaire, User, db
from ..models.constants import (ETAPE_A_CONFIRMER, ETAPE_A_ENVOYER,
ETAPE_COM_A_MODERER, ETAPE_COM_PUBLIE,
ETAPE_ENVOYE)
ETAPE_ENVOYE, ETAPE_NA)
from ..tools.files import generer_demande, handle_upload
from ..tools.routing import not_found, redirect_back, remote_addr, require_user
from ..tools.text import check_suivi, slugify
......@@ -66,7 +66,8 @@ def setup_routes(app):
return render_template(
'list.html.j2',
parlementaires=qs
parlementaires=qs,
full_list=True
)
@app.route('/parlementaires/<id>', endpoint='parlementaire')
......
......@@ -4,8 +4,8 @@ from flask import flash, redirect, render_template, request, session, url_for
from sqlalchemy.orm import joinedload
from ..models import Action, User, db
from ..models.constants import ETAPE_ENVOYE
from ..models import Action, Parlementaire, User, db
from ..models.constants import ETAPE_A_CONFIRMER, ETAPE_ENVOYE
from ..tools.routing import not_found, redirect_back, require_user
from ..tools.text import check_email, check_password, sanitize_hard
......@@ -124,3 +124,30 @@ def setup_routes(app):
return redirect_back()
return render_template('profil.html.j2', user=user, envois=envois)
@app.route('/mes-actions', endpoint='mes_actions')
@require_user
def mes_actions():
user = User.query.filter(User.id == session['user']['id']) \
.options(joinedload(User.abonnements)) \
.first()
if not user:
return not_found()
acts = Action.query \
.filter(Parlementaire.id == Action.parlementaire_id) \
.filter(Action.etape.in_([ETAPE_ENVOYE,
ETAPE_A_CONFIRMER])) \
.filter(Action.user_id == session['user']['id']) \
.exists()
qs = Parlementaire.query.filter(acts) \
.options(joinedload(Parlementaire.groupe)) \
.order_by(Parlementaire.nom) \
.all()
return render_template(
'list.html.j2',
parlementaires=qs,
full_list=False
)
......@@ -6,19 +6,29 @@
{% block content %}
<section class="panel panel-default">
<header class="panel-heading">
<b>Liste des {{ parlementaires|length }} parlementaires</b>
</header>
<article class="panel-body">
<div class="input-group">
<span class="input-group-addon" id="search-header">Filtrer les parlementaires</span>
<input type="search" autocomplete="off" autofocus="autofocus" class="form-control" id="search" placeholder="Nom, groupe, circonscription..." value="{{ request.args.q|e }}" aria-describedby="search-header">
<span class="input-group-btn">
<button class="btn btn-primary" type="button" id="search-clear" style="display: none;">Effacer le filtre</button>
</span>
</div>
</article>
{% if full_list %}
<header class="panel-heading">
<b>Liste des {{ parlementaires|length }} parlementaires</b>
</header>
<article class="panel-body">
<div class="input-group">
<span class="input-group-addon" id="search-header">Filtrer les parlementaires</span>
<input type="search" autocomplete="off" autofocus="autofocus" class="form-control" id="search" placeholder="Nom, groupe, circonscription..." value="{{ request.args.q|e }}" aria-describedby="search-header">
<span class="input-group-btn">
<button class="btn btn-primary" type="button" id="search-clear" style="display: none;">Effacer le filtre</button>
</span>
</div>
</article>
{% else %}
<header class="panel-heading">
<b>Mes actions</b>
</header>
{% endif %}
<table class="table table-condensed table-striped sortable searchable">
<thead>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment