Browse Source

Administration des users et des votes

Guillaume Subiron 13 years ago
parent
commit
2c48c6a192
5 changed files with 107 additions and 4 deletions
  1. 17 3
      main.py
  2. 37 0
      templates/admin_users.html
  3. 49 0
      templates/admin_votes.html
  4. 3 1
      templates/layout.html
  5. 1 0
      templates/show_roles.html

+ 17 - 3
main.py

@@ -144,6 +144,13 @@ def user_password(userid):
 #------------
 # User admin
 
+@app.route('/users/admin/list')
+def admin_users():
+    if not session.get('user').get('is_admin'):
+        abort(401)
+    users = query_db('select * from users order by id desc')
+    return render_template('admin_users.html', users=users)
+
 @app.route('/users/admin/add', methods=['GET', 'POST'])
 def add_user():
     if not session.get('user').get('is_admin'):
@@ -207,13 +214,13 @@ def del_role(idrole):
 def show_votes(votes):
     today = date.today()
     active_button = votes
-    basequery = 'select *, roles.name as rolename from votes join roles on roles.id=votes.id_role'
+    basequery = 'select *, roles.name as rolename from votes join roles on roles.id=votes.id_role where open=1'
     if votes == 'all':
         votes = query_db(basequery + ' order by id desc')
     elif votes == 'archive':
-        votes = query_db(basequery + ' where date_end < (?) order by id desc', [today])
+        votes = query_db(basequery + ' and date_end < (?) order by id desc', [today])
     elif votes == 'current':
-        votes = query_db(basequery + ' where date_end >= (?) order by id desc', [today])
+        votes = query_db(basequery + ' and date_end >= (?) order by id desc', [today])
     else:
         abort(404)
     return render_template('show_votes.html', votes=votes, active_button=active_button)
@@ -248,6 +255,13 @@ def show_vote(idvote):
 #-------------
 # Votes admin
 
+@app.route('/votes/admin/list')
+def admin_votes():
+    if not session.get('user').get('is_admin'):
+        abort(401)
+    votes = query_db('select *, roles.name as rolename from votes join roles on roles.id=votes.id_role order by id desc')
+    return render_template('admin_votes.html', votes=votes)
+
 @app.route('/votes/admin/add', methods=['GET', 'POST'])
 def add_vote():
     if not session.get('user').get('is_admin'):

+ 37 - 0
templates/admin_users.html

@@ -0,0 +1,37 @@
+{% extends "layout.html" %}
+{% block subtitle %}Administrer les utilisateurs{% endblock %}
+{% block body %}
+<div class="row">
+  <hr />
+  {% if not users %}
+  <div class="alert">Il n'y a aucun user.</div>
+  {% else %}
+  <table class="table table-striped">
+    <thead>
+    <tr>
+      <th>E-mail</th>
+      <th>Nom</th>
+      <th>Groupes</th>
+      <th>Admin</th>
+      <th>Actions</th>
+    </tr>
+    </thead>
+    <tbody>
+    {% for user in users %}
+    <tr>
+      <td>{{ user.email }}</td>
+      <td>{{ user.name }}</td>
+      <td></td>
+      <td>{% if user.is_admin %}<span class="label label-success">Oui</span>{% else %}<span class="label">Non</span>{% endif %}</td>
+      <td>
+        <a href="" class="btn btn-mini">Éditer</a>
+        <a href="" class="btn btn-mini btn-danger">Supprimer</a>
+      </td>
+    </tr>
+    {% endfor %}
+    </tbody>
+  </table>
+  <p>
+  {% endif %}
+{% endblock %}
+

+ 49 - 0
templates/admin_votes.html

@@ -0,0 +1,49 @@
+{% extends "layout.html" %}
+{% block subtitle %}Administrer les votes{% endblock %}
+{% block body %}
+<div class="row">
+  <hr />
+  {% if not votes %}
+  <div class="alert">Il n'y a aucun vote.</div>
+  {% else %}
+  <table class="table table-striped">
+    <thead>
+    <tr>
+      <th>Nom</th>
+      <th>Statut</th>
+      <th>Deadline</th>
+      <th>Groupe</th>
+      <th>Catégorie</th>
+      <th>Options</th>
+      <th>Actions</th>
+    </tr>
+    </thead>
+    <tbody>
+    {% for vote in votes %}
+    <tr>
+      <td>{{ vote.title }}</td>
+      <td>{% if vote.is_open %}<span class="label label-success">Ouvert</span>{% else %}<span class="label label-important">Fermé</span>{% endif %}</td>
+      <td>{{ vote.date_end }}</td>
+      <td>{{ vote.rolename }}</td>
+      <td>{{ vote.category }}</td>
+      <td>
+        {% if vote.is_transparent %}<span class="label">transparent</span>{% endif %}
+        {% if vote.is_public %}<span class="label">public</span>{% endif %}
+        {% if vote.is_multiplechoice %}<span class="label">choix multiple</span>{% endif %}
+      </td>
+      <td><a href="{{ url_for('edit_vote', voteid=vote.id) }}" class="btn btn-mini">Éditer</a></td>
+    </tr>
+    {% endfor %}
+    </tbody>
+  </table>
+  <p>
+  <strong>Légende :</strong>
+  <ul class="unstyled">
+    <li><span class="label">transparent</span> : Les utilisateurs peuvent voir les votes des autres</li>
+    <li><span class="label">public</span> : Tout le monde peut voir le vote</li>
+    <li><span class="label">choix multiple</span> : Les utilisateurs peuvent effectuer plusieurs choix</li>
+  </ul>
+  </p>
+  {% endif %}
+{% endblock %}
+

+ 3 - 1
templates/layout.html

@@ -26,10 +26,12 @@
       <a href="#" class="btn btn-warning dropdown-toggle" data-toggle="dropdown">Admin <b class="caret"></b></a>
       <ul class="dropdown-menu pull-right">
         <li><a href="{{ url_for('add_vote') }}">Nouveau vote</a></li>
+        <li><a href="{{ url_for('admin_votes') }}">Administrer les votes</a></li>
         <li class="divider"></li>
         <!--<li><a href="404">Utilisateurs</a></li>-->
-        <li><a href="{{ url_for('show_roles') }}">Groupes</a></li>
         <li><a href="{{ url_for('add_user') }}">Nouvel utilisateur</a></li>
+        <li><a href="{{ url_for('admin_users') }}">Administrer les utilisateurs</a></li>
+        <li><a href="{{ url_for('show_roles') }}">Administrer les groupes</a></li>
       </ul>
       {% endif %}
     </div>

+ 1 - 0
templates/show_roles.html

@@ -1,4 +1,5 @@
 {% extends "layout.html" %}
+{% block subtitle %}Administrer les votes{% endblock %}
 {% block body %}
 <div class="row">
 <div class="span6 well">