Ajout d'une barre de menu, réécriture des formulaires, ajout d'attribut dans la table...
authorGuillaume Subiron <maethor@subiron.org>
Fri, 25 May 2012 18:07:18 +0000 (20:07 +0200)
committerJulien Rabier <taziden@flexiden.org>
Fri, 25 May 2012 19:25:39 +0000 (21:25 +0200)
main.py
schema.sql
templates/layout.html
templates/login.html
templates/new_vote.html [new file with mode: 0644]
templates/show_votes.html

diff --git a/main.py b/main.py
index 57c876b..a8bc229 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -34,18 +34,34 @@ def home():
 
 @app.route('/admin/votes')
 def show_votes():
-    cur = g.db.execute('select title, description, date from votes order by id desc')
-    votes = [dict(title=row[0], description=row[1], date=row[2]) for row in cur.fetchall()]
+    cur = g.db.execute('select title, description, date_begin, date_end from votes order by id desc')
+    votes = [dict(title=row[0], description=row[1], date_begin=row[2], date_end=row[3], 
+        pourcent=60) for row in cur.fetchall()]
     return render_template('show_votes.html', votes=votes)
 
+@app.route('/admin/votes/new')
+def new_vote():
+    if not session.get('logged_in'):
+        abort(401)
+    return render_template('new_vote.html')
+
 @app.route('/admin/vote/add', methods=['POST'])
 def add_vote():
     if not session.get('logged_in'):
         abort(401)
-    daten = date.today() + timedelta(days=60)
+    daten = date.today() + timedelta(days=int(request.form['days']))
     ndate = daten.strftime('%d %B %Y')
-    g.db.execute('insert into votes (title, description, date) values (?, ?, ?)',
-            [request.form['title'], request.form['description'], ndate])
+    transparent = 0
+    public = 0
+    multiplechoice = 0
+    if request.form['transparent'] == "on":
+        transparent = 1
+    if request.form['public'] == "on":
+        public = 1
+    if request.form['multiplechoice'] == "on":
+        multiplechoice = 1
+    g.db.execute('insert into votes (title, description, date_end, is_transparent, is_public, is_multiplechoice) values (?, ?, ?, ?, ?, ?)',
+            [request.form['title'], request.form['description'], ndate, transparent, public, multiplechoice])
     g.db.commit()
     flash('New entry was successfully posted')
     return redirect(url_for('home'))
@@ -61,6 +77,8 @@ def login():
         else:
             session['logged_in'] = True
             session['nickname'] = request.form['username']
+            if session['nickname'] == 'admin':
+                session['is_admin'] = True
             flash('You were logged in')
             return redirect(url_for('home'))
     return render_template('login.html', error=error)
index d138caa..4b23934 100644 (file)
@@ -1,8 +1,20 @@
 drop table if exists votes;
 create table votes (
-    id integer primary key autoincrement,
-    title string not null,
-    description string not null,
-    date string not null
+    id INTEGER primary key autoincrement,
+    title TEXT not null,
+    description TEXT,
+    category TEXT,
+    date_begin INTEGER default CURRENT_TIMESTAMP not null,
+    date_end INTEGER not null,
+    is_transparent INTEGER default 1 not null, 
+    is_public INTEGER default 1 not null,
+    is_multiplechoice INTEGER default 1 not null,
+    is_weighted INTEGER default 0 not null,
+    is_closed INTEGER default 0 not null
+    --id_author INTEGER not null,
+    --id_role INTEGER,
+    --FOREIGN KEY(id_author) REFERENCES user(id),
+    --FOREIGN KEY(id_role) REFERENCES role(id)
 );
 
+
index 0ac3eb6..0234d90 100644 (file)
     <!-- javascript -->
   </head>
 <body>
-  <!--
-<div class="navbar">
-  <div class="navbar-inner">
-    <div class="container">
-      <a class="brand" href="/">Cavote</a>
-      <ul class="nav">
-      </ul>
-      <ul class="nav pull-right">
-        <li class="divider-vertical"></li>
-        {% if not session.logged_in %}
-        <li><a href="{{ url_for('login') }}"><i class="icon-user icon-white"></i> Connexion</a></li>
-        {% else %}
-        <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-user icon-white"></i> {{ session.nickname }} <b class="caret"></b></a>
-          <ul class="dropdown-menu">
-            <li><a href=""><i class="icon-cog"></i> Paramètres</a></li>
-            <li><a href="{{ url_for('logout') }}"><i class="icon-off"></i> Déconnexion</a></li>
-          </ul>
-        </li>
-        {% endif %}
-      <ul class="nav">
-    </div>
-  </div>
-</div>
-  -->
 
 <div class="container-fluid">
 
+<header>
   <div class="btn-toolbar">
+    <div class="btn-group">
+      <a class="btn active" href="/">Accueil</a>
+      <a class="btn" href="">Votes en cours</a>
+      <a class="btn" href="{{ url_for('show_votes') }}">Archives</a>
+      {% if session.is_admin %}
+      <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('new_vote') }}">Nouveau vote</a></li>
+      </ul>
+      {% endif %}
+    </div>
     <div class="btn-group pull-right">
       {% if not session.logged_in %}
-      <a class="btn btn-primary" href="{{ url_for('login') }}"><i class="icon-user icon-white"></i> Connexion</a></li>
+      <a class="btn btn-primary" href="{{ url_for('login') }}"><i class="icon-user icon-white"></i> Connexion</a>
       {% else %}
       <a href="#" class="btn"><i class="icon-user"></i> {{ session.nickname }}</a>
       <a href="#" class="btn dropdown-toggle" data-toggle="dropdown"><b class="caret"></b></a>
@@ -56,8 +44,9 @@
       {% endif %}
     </div>
   </div>
+</header>
 
-<h1 class="page-header"><a href="/" style="text-decoration:none;">Outil de vote du CA FFDN</a></h1>
+<h1 class="page-header">Outil de vote du CA FFDN</h1>
 {% with messages = get_flashed_messages() %}
   {% if messages %}
     {% for message in messages %}
index 6f70bb7..334caa1 100644 (file)
@@ -1,14 +1,19 @@
 {% extends "layout.html" %}
 {% block body %}
-  <h2>Login</h2>
-  {% if error %}<p class=error><strong>Error:</strong> {{ error }}{% endif %}
-  <form action="{{ url_for('login') }}" method=post>
-    <dl>
-      <dt>Username:
-      <dd><input type=text name=username>
-      <dt>Password:
-      <dd><input type=password name=password>
-      <dd><input type=submit value=Login>
-    </dl>
-  </form>
+<div class="row">
+  <div class="span3 well">
+    {% if error %}<div class="alert alert-error"><strong>Error:</strong> {{ error }}</div>{% endif %}
+    <form action="{{ url_for('login') }}" method="post">
+    <fieldset><legend>Connexion</legend>
+      <label for="username">E-mail</label>
+      <input type="text" name="username" id="username" />
+      <label for="password">Mot de passe</label>
+      <input type="password" name="password" id="password" />
+      <br />
+      <input type="submit" class="btn btn-primary" value="Connexion" />
+    </fieldset>
+    </form>
+    <p><a href="">Mot de passe perdu ?</a></p>
+  </div>
+</div>
 {% endblock %}
diff --git a/templates/new_vote.html b/templates/new_vote.html
new file mode 100644 (file)
index 0000000..ecd7ba2
--- /dev/null
@@ -0,0 +1,77 @@
+{% extends "layout.html" %}
+{% block body %}
+
+<div class="row">
+  <div class="span7 well">
+<form action="{{ url_for('add_vote') }}" method="post" class="form-horizontal">
+<fieldset><legend>Ajouter un vote</legend>
+  <div class="control-group">
+    <label class="control-label" for="title">Titre</label>
+    <div class="controls">
+      <input type="text" size=30 name="title" id="title" />
+      <span class="help-inline"><font color="red">*</font></span>
+    </div>
+  </div>
+  <div class="control-group">
+    <label class="control-label" for="description">Description</label>
+    <div class="controls">
+      <textarea class="input-xlarge" name="description" id="description"></textarea>
+    </div>
+  </div>
+  <div class="control-group">
+    <label class="control-label" for="category">Catégorie</label>
+    <div class="controls">
+      <input type="text" data-provide="typeahead" data-source='["ca","membres"]' size=30 name="category" id="category" />
+    </div>
+  </div>
+  <div class="control-group">
+    <label class="control-label" for="role">Groupe</label>
+    <div class="controls">
+      <select name="role" id="role">
+        <option selected>Tous</option>
+        <option>CA</option>
+        <option>Membres</option>
+      </select>
+      <p class="help-block">Groupe d'utilisateur concernés par le vote et ayant le droit de voter</p>
+    </div>
+  </div>
+  <div class="control-group">
+    <label class="control-label" for="days">Durée (jours)</label>
+    <div class="controls">
+      <select class="span1" name="days" id="days">
+        {% for i in range(1, 31) %}
+        {% if i == 20 %}
+        <option selected>{{ i }}</option>
+        {% else %}
+        <option>{{ i }}</option>
+        {% endif %}
+        {% endfor %}
+      </select>
+    </div>
+  </div>
+  <div class="control-group">
+    <label class="control-label">Options</label>
+    <div class="controls">
+      <label class="checkbox">
+        <input type="checkbox" name="transparent" />
+        Les votants peuvent-ils voir le choix des autres ?
+      </label>
+      <label class="checkbox">
+        <input type="checkbox" name="public" />
+        Le vote est-il visible par tous ?
+      </label>
+      <label class="checkbox">
+        <input type="checkbox" name="multiplechoice" />
+        Les votants peuvent-ils choisir plusieurs options ?
+      </label>
+    </div>
+  </div>
+  <div class="form-actions">
+    <input type="submit" class="btn btn-primary" value="Publier" />
+  </div>
+</fieldset>
+</form>
+  </div>
+</div>
+
+{% endblock %}
index 9aec632..079632b 100644 (file)
@@ -1,21 +1,18 @@
 {% extends "layout.html" %}
 {% block body %}
-
-<br />
-<br />
   <h2>Liste des votes</h2>
-  <ul class=votes>
   {% for vote in votes %}
-  <li style="list-style-image: url(/static/img/icon-cog.png)"><h2>{{ vote.title }}</h2>
-    <br />
-    <div class="well" style="width:80%">
+  <article>
+    <div class="well">
+    <h3>{{ vote.title }}</h3>
+    <hr />
     <div class="row">
     <div class="span4">
-        <h4>Deadline : {{ vote.date }} </h4>
+        <h4>Deadline : {{ vote.date_end }} </h4>
         <br />
     <div class="progress progress-striped">
         <div class="bar"
-            style="width: 60%;"></div>
+            style="width: {{ vote.pourcent }}%;"></div>
     </div></div>
     <div class="span4">  
         <h4>Documents</h4>
     <h4>Notes</h4>
         {{ vote.description|safe }}
     </div></div></div>
+  </article>
   {% else %}
-    <li>Pas encore de votes</li>
+  <div class="alert">Il n'y a pas encore de votes. Désolé.</div>
   {% endfor %}
-  </ul>
-  {% if session.logged_in %}
-    <h2> Ajouter un vote </h2>
-    <form action="{{ url_for('add_vote') }}" method=post class=add-vote>
-      <dl>
-        <dt>Question soumise au vote&nbsp;:
-        <dd><input type=text size=30 name=title>
-        <dt>Description (facultative)&nbsp;:
-        <dd><textarea name=description rows=5 cols=40></textarea>
-        <dd><input type=submit class="btn" value=Paf>
-      </dl>
-    </form>
-  {% endif %}
-    Retour à l'<a href="/">accueil</a>
-
 {% endblock %}