Browse Source

Nb votes and max votes displayed in progress bar

Guillaume Subiron 13 years ago
parent
commit
f43f9263fc
4 changed files with 27 additions and 10 deletions
  1. 6 4
      main.py
  2. 1 1
      schema.sql
  3. 7 2
      templates/vote.html
  4. 13 3
      templates/votes.html

+ 6 - 4
main.py

@@ -19,10 +19,10 @@ SECRET_KEY = '{J@uRKO,xO-PK7B,jF?>iHbxLasF9s#zjOoy=+:'
 DEBUG = True
 TITLE = u"Cavote FFDN"
 EMAIL = '"' + TITLE + '"' + ' <' + u"cavote@ffdn.org" + '>'
-BASEURL = "http://localhost:5000"
+BASEURL = "http://localhost:5000" # :TODO:maethor:120605: Find a cleaner way to do this
 VERSION = "cavote 0.0.1"
 SMTP_SERVER = "10.33.33.30"
-PATTERNS = {u'Oui/Non': [u'Oui', u'Non'], u'Oui/Non/Peut-être': [u'Oui', u'Non', u'Peut-être']}
+PATTERNS = {u'Oui/Non': [u'Oui', u'Non'], u'Oui/Non/Blanc': [u'Oui', u'Non', u'Blanc'], u'Oui/Non/Peut-être': [u'Oui', u'Non', u'Peut-être']}
 
 app = Flask(__name__)
 app.config.from_object(__name__)
@@ -323,7 +323,7 @@ def votes(votes):
     today = date.today()
     active_button = votes
     max_votes ='select id_group, count(*) as max_votes from user_group group by id_group'
-    basequery = 'select votes.*, max_votes from votes join (' + max_votes + ') as max_votes on votes.id_group = max_votes.id_group'
+    basequery = 'select votes.*, max_votes from votes left join (' + max_votes + ') as max_votes on votes.id_group = max_votes.id_group'
     nb_votes = 'select id_vote, count(*) as nb_votes from (select id_user, id_vote from user_choice join choices on id_choice = choices.id group by id_user, id_vote) group by id_vote'
     basequery = 'select * from (' + basequery + ') left join (' + nb_votes + ') on id = id_vote'
     basequery = 'select *, votes.id as voteid, groups.name as groupname from (' + basequery + ') as votes join groups on groups.id = id_group where is_open=1'
@@ -342,7 +342,8 @@ def votes(votes):
     for vote in votes:
         if not vote.get('nb_votes'):
             vote['nb_votes'] = 0 
-        vote['percent'] = int((float(vote['nb_votes']) / float(vote['max_votes'])) * 100)
+        if vote.get('max_votes'):
+            vote['percent'] = int((float(vote['nb_votes']) / float(vote['max_votes'])) * 100)
     return render_template('votes.html', votes=votes, active_button=active_button)
 
 #------
@@ -416,6 +417,7 @@ def vote(idvote):
             tmp = query_db('select id_vote, count(*) as nb from (select id_user, id_vote from user_choice join choices on id_choice = choices.id group by id_user, id_vote) where id_vote = ? group by id_vote', [idvote], one=True)
             if tmp is None:
                 vote['percent'] = 0
+                vote['nb_votes'] = 0
             else:
                 vote['nb_votes'] = tmp['nb']
                 vote['percent'] = int((float(vote['nb_votes']) / float(vote['max_votes'])) * 100)

+ 1 - 1
schema.sql

@@ -47,7 +47,7 @@ create table votes (
     is_weighted BOOLEAN DEFAULT 0 NOT NULL,
     is_open BOOLEAN DEFAULT 0 NOT NULL,
     is_terminated BOOLEAN DEFAULT 0 NOT NULL,
-    id_author INTEGER DEFAULT 1 NOT NULL, -- :COMMENT:maethor:120528: not null ?
+    id_author INTEGER DEFAULT 1 NOT NULL,
     id_group INTEGER DEFAULT 1 NOT NULL,
     FOREIGN KEY(id_author) REFERENCES users (id) ON DELETE SET DEFAULT,
     FOREIGN KEY(id_group) REFERENCES groups (id),

+ 7 - 2
templates/vote.html

@@ -75,10 +75,15 @@
 
 <div class="span3">
 <h3>Informations</h3>
-<strong>Avancement : </strong> {{ vote.nb_votes }} / {{ vote.max_votes }}
+{% if vote.nb_votes == 0 %}
+<div class="progress progress-striped progress-danger">
+  <div class="bar" style="width: 100%;"><strong>{{ vote.nb_votes }} / {{ vote.max_votes }}</strong></div>
+</div>
+{% else %}
 <div class="progress progress-striped {% if vote.nb_votes == vote.max_votes %}progress-success{% endif %}">
-  <div class="bar" style="width: {{ vote.percent }}%;"></div>
+  <div class="bar" style="width: {{ vote.percent }}%;"><strong>{{ vote.nb_votes }} / {{ vote.max_votes }}</strong></div>
 </div>
+{% endif %}
 <dl class="dl-horizontal">
   <dt>Publié par <dd><code>maethor</code>
   <dt>Début le <dd><code>{{ vote.date_begin }}</code>

+ 13 - 3
templates/votes.html

@@ -6,10 +6,20 @@ Liste des votes
   {% for vote in votes %}
   <div>
     <div class="row well">
-      <div class="span4">
+      <div class="span5">
         <h3><a href="{{ url_for('vote', idvote=vote.voteid) }}">{{ vote.title }}</a></h3>
-        <div class="progress progress-striped {% if vote.nb_votes == vote.max_votes %}progress-success{% endif %}">
-          <div class="bar" style="width: {{ vote.percent }}%;"></div>
+        <div class="row">
+          <div class="span4">
+            {% if vote.nb_votes == 0 %}
+            <div class="progress progress-striped progress-danger">
+              <div class="bar" style="width: 100%;"><strong>{{ vote.nb_votes }} / {{ vote.max_votes }}</strong></div>
+            </div>
+            {% else %}
+            <div class="progress progress-striped {% if vote.nb_votes == vote.max_votes %}progress-success{% endif %}">
+              <div class="bar" style="width: {{ vote.percent }}%;"><strong>{{ vote.nb_votes }} / {{ vote.max_votes }}</strong></div>
+            </div>
+            {% endif %}
+          </div>
         </div>
       </div>
       <div class="span3">