Users can see waiting votes, votes can be terminated
authorGuillaume Subiron <maethor@subiron.org>
Tue, 5 Jun 2012 09:58:16 +0000 (11:58 +0200)
committerJulien Rabier <taziden@flexiden.org>
Tue, 5 Jun 2012 10:24:26 +0000 (12:24 +0200)
main.py
schema.sql
templates/admin_vote_edit.html
templates/admin_votes.html
templates/layout.html
templates/vote.html
templates/votes.html

diff --git a/main.py b/main.py
index e86e453..22d8c87 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -298,9 +298,13 @@ def votes(votes):
     if votes == 'all':
         votes = query_db(basequery + ' order by id desc')
     elif votes == 'archive':
-        votes = query_db(basequery + ' and date_end < (?) order by id desc', [today])
+        votes = query_db(basequery + ' and is_terminated=1 order by id desc')
     elif votes == 'current':
-        votes = query_db(basequery + ' and date_end >= (?) order by id desc', [today])
+        votes = query_db(basequery + ' and is_terminated=0 order by id desc')
+    elif votes == 'waiting':
+        basequery = 'select votes.* from user_group join (' + basequery + ') as votes on votes.id_group = user_group.id_group where user_group.id_user = ?'
+        already_voted = 'select id_vote from user_choice join choices on user_choice.id_choice = choices.id where id_user = ?'
+        votes = query_db(basequery + ' and votes.id not in (' + already_voted + ') and is_terminated=0', [get_userid(), get_userid()])
     else:
         abort(404)
     for vote in votes:
@@ -322,17 +326,16 @@ def can_see_vote(idvote, iduser=-1):
             return False
     return True
 
-
-
 def can_vote(idvote, iduser=-1):
     vote = query_db('select * from votes where id=?', [idvote], one=True)
     if vote is None:
         return False
-    if iduser > 0: 
-        if can_see_vote(idvote, iduser): 
-            if not has_voted(idvote, iduser):
-                if query_db('select * from user_group where id_user = ? and id_group = ?', [iduser, vote['id']], one=True):
-                    return True
+    if not vote['is_finished']:
+        if iduser > 0: 
+            if can_see_vote(idvote, iduser): 
+                if not has_voted(idvote, iduser):
+                    if query_db('select * from user_group where id_user = ? and id_group = ?', [iduser, vote['id']], one=True):
+                        return True
     return False
 
 def has_voted(idvote, iduser=-1):
@@ -459,14 +462,19 @@ def admin_vote_edit(voteid):
             if 'public' in request.form.keys():
                 public = 1
             isopen = 0
+            isterminated = 0
             if request.form['status'] == 'Ouvert':
                 choices = query_db('select id_vote, count(*) as nb from choices where id_vote = ? group by id_vote', [voteid], one=True)
                 if choices is not None and choices['nb'] >= 2:
                     isopen = 1
                 else:
                     flash(u'Vous devez proposer au moins deux choix pour ouvrir le vote.', 'error')
-            g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ? where id = ?',
-                    [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, voteid])
+            elif request.form['status'] == u'Terminé':
+                isterminated = 1
+                if vote['is_open']:
+                    isopen = 1
+            g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ?, is_terminated = ? where id = ?',
+                    [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, isterminated, voteid])
             g.db.commit()
             vote = query_db('select * from votes where id = ?', [voteid], one=True)
             flash(u"Le vote a bien été mis à jour.", "success")
index 7f6a0bc..541fa23 100644 (file)
@@ -18,7 +18,7 @@ create table users (
 
 create table groups (
     id INTEGER primary key autoincrement,
-    name TEXT,
+    name TEXT unique not null,
     system INTEGER default 0 not null 
 );
 
@@ -42,6 +42,7 @@ create table votes (
     is_multiplechoice INTEGER default 1 not null,
     is_weighted INTEGER default 0 not null,
     is_open INTEGER default 0 not null,
+    is_terminated INTEGER default 0 not null,
     id_author INTEGER, -- :COMMENT:maethor:120528: not null ?
     id_group INTEGER default 1 not null,
     FOREIGN KEY(id_author) REFERENCES users(id)
@@ -76,5 +77,5 @@ create table user_choice (
 insert into users (email, password, name, organization, is_admin, key) values ("admin@admin.fr", "d033e22ae348aeb5660fc2140aec35850c4da997", "Toto (admin) Tata", "World corp", 1, "test"); -- mdp = admin
 insert into groups (id, name, system) values (1, "Tous", 1);
 insert into groups (name) values ("CA");
-insert into groups (name) values ("Members");
+insert into groups (name) values ("Membres");
 
index d2f4ac1..a0adb07 100644 (file)
                     <input type="checkbox" name="public" {% if vote.is_public == 1 %} checked {% endif %}/>
                     Le vote est-il visible par tous ?
                   </label>
+                {% if not vote.is_terminated == 1 %}
                   <label class="checkbox">
                     <input type="checkbox" name="multiplechoice" {% if vote.is_multiplechoice == 1 %} checked {% endif %} disabled/>
                     Les votants peuvent-ils choisir plusieurs options ?
                   </label>
+                {% endif %}
                 </div>
               </div>
             </div>
         <label class="control-label" for="status">Statut</label>
         <div class="controls">
           <select class="span2" name="status" id="status">
-            {% if vote.is_open %}
-              <option>Fermé</option>
-              <option selected>Ouvert</option>
+            {% if vote.is_terminated == 1 %}
+                  <option>Fermé</option>
+                  <option>Ouvert</option>
+                  <option selected>Terminé</option>
             {% else %}
-              <option selected>Fermé</option>
-              <option>Ouvert</option>
+                {% if vote.is_open == 1 %}
+                  <option>Fermé</option>
+                  <option selected>Ouvert</option>
+                  <option>Terminé</option>
+                {% else %}
+                  <option selected>Fermé</option>
+                  <option>Ouvert</option>
+                {% endif %}
             {% endif %}
           </select>
         </div>
     </form>
   </div>
 
+  {% if not vote.is_terminated == 1%}
   <div class="span5 well pull-right">
     <fieldset><legend>Choix</legend>
       <table class="table table-stripped table-condensed">
       </table>
     </fieldset>
   </div>
+  {% endif %}
 
   <div class="span5 well pull-right">
     <fieldset><legend>Pièces jointes</legend>
index 786cec3..e3faf72 100644 (file)
@@ -22,7 +22,7 @@
     {% 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>{% if vote.is_terminated %}<span class="label label-sucess">Terminé</span>{% else %}{% if vote.is_open %}<span class="label label-info">Ouvert</span>{% else %}<span class="label label-important">Fermé</span>{% endif %}{% endif %}</td>
       <td>{{ vote.date_end }}</td>
       <td>{{ vote.groupname }}</td>
       <td>{{ vote.category }}</td>
index 321610b..6fe38aa 100644 (file)
@@ -41,7 +41,7 @@
       <a href="{{ url_for('user', userid=session.user.id) }}" class="btn"><i class="icon-user"></i> {{ session.user.name }}</a>
       <a href="#" class="btn dropdown-toggle" data-toggle="dropdown"><b class="caret"></b></a>
       <ul class="dropdown-menu pull-right">
-        <li><a href=""><i class="icon-comment"></i> Votes en attente</a></li>
+        <li><a href="{{ url_for('votes', votes='waiting') }}"><i class="icon-comment"></i> Votes en attente</a></li>
         <li><a href="{{ url_for('user_edit', userid=session.user.id) }}"><i class="icon-cog"></i> Paramètres</a></li>
         <li class="divider"></li>
         <li><a href="{{ url_for('logout') }}"><i class="icon-off"></i> Déconnexion</a></li>
index 86b020d..8d6e9dd 100644 (file)
@@ -14,7 +14,9 @@
       {% for choice in choices %}
       <th>{{ choice.name }}</th>
       {% endfor %}
+      {% if 'user' in 'session' %}
       <th></th>
+      {% endif %}
     </tr>
   </thead>
 
@@ -29,7 +31,9 @@
       {% else %}
       <td class="no"></td>{% endif %}
       {% endfor %}
-      <td>{% if 'user' in session and user.userid == session.user.id %}<a href="{{ url_for('vote_deletechoices', idvote=vote.id, iduser=session.user.id) }}" class="btn btn-mini btn-danger" title="Supprimer"><i class="icon-remove icon-white"></a>{% endif %}</td>
+      {% if 'user' in 'session' %}
+      <td>{% if user.userid == session.user.id %}<a href="{{ url_for('vote_deletechoices', idvote=vote.id, iduser=session.user.id) }}" class="btn btn-mini btn-danger" title="Supprimer"><i class="icon-remove icon-white"></a>{% endif %}</td>
+      {% endif %}
     </tr>
   {% endif %}
   {% endfor %}
@@ -60,7 +64,9 @@
       {% for choice in choices %}
       <td>{{ choice.nb }}</td>
       {% endfor %}
+      {% if 'user' in 'session' %}
       <td></td>
+      {% endif %}
     </tr>
   {% endif %}
   </tfoot>
index 88ffee5..e52b94b 100644 (file)
@@ -4,7 +4,7 @@ Liste des votes
 {% endblock %}
 {% block body %}
   {% for vote in votes %}
-  <article>
+  <div>
     <div class="row well">
       <div class="span4">
         <h3><a href="{{ url_for('vote', idvote=vote.voteid) }}">{{ vote.title }}</a></h3>
@@ -23,7 +23,7 @@ Liste des votes
       {{ vote.description|safe }}
       </p>
     </div>
-  </article>
+  </div>
   {% else %}
   <div class="alert">Il n'y a pas encore de votes. Désolé.</div>
   {% endfor %}