Browse Source

Added metas to vote view, added attachments table

Guillaume Subiron 13 years ago
parent
commit
251888ac34
3 changed files with 35 additions and 4 deletions
  1. 3 2
      main.py
  2. 8 0
      schema.sql
  3. 24 2
      templates/vote.html

+ 3 - 2
main.py

@@ -233,12 +233,13 @@ def can_vote(idvote, iduser=-1):
 
 @app.route('/vote/<idvote>')
 def show_vote(idvote):
-    vote = query_db('select * from votes where id=?', [idvote], one=True)
+    vote = query_db('select *, roles.name as rolename from votes join roles on roles.id=votes.id_role where votes.id=?', [idvote], one=True)
     if vote is None:
         abort(404)
     if can_see_vote(idvote, session.get('user').get('id')):
         choices = query_db('select * from choices where id_vote=?', [idvote])
-        return render_template('vote.html', vote=vote, choices=choices, can_vote=can_vote(idvote, session.get('user').get('id')))
+        attachments = query_db('select * from attachments where id_vote=?', [idvote])
+        return render_template('vote.html', vote=vote, attachments=attachments, choices=choices, can_vote=can_vote(idvote, session.get('user').get('id')))
     flash('Vous n\'avez pas le droit de voir ce vote, désolé.')
     return(url_for('home'))
 

+ 8 - 0
schema.sql

@@ -1,4 +1,5 @@
 drop table if exists choices;
+drop table if exists attachments;
 drop table if exists votes;
 drop table if exists roles;
 drop table if exists users;
@@ -37,6 +38,13 @@ create table votes (
     FOREIGN KEY(id_role) REFERENCES roles(id)
 );
 
+create table attachments (
+    url TEXT not null,
+    id_vote INTEGER not null,
+    FOREIGN KEY(id_vote) REFERENCES vote(id),
+    PRIMARY KEY(url, id_vote)
+);
+
 create table choices (
     id INTEGER primary key autoincrement,
     name TEXT not null,

+ 24 - 2
templates/vote.html

@@ -1,8 +1,8 @@
 {% extends "layout.html" %}
 {% block body %}
-<h2>{{ vote.title }}</h2>
 <div class="row">
-<div class="span10 offset1">
+<div class="span9">
+<h2 class='page-header'>{{ vote.title }}</h2>
 <table class="table table-condensed table-striped table-bordered">
   <thead>
     <tr>
@@ -53,6 +53,28 @@
   </tfoot>
 </table>
 </div>
+
+<div class="span3">
+<h3>Informations</h3>
+<dl class="dl-horizontal">
+  <dt>Publié par <dd><code>maethor</code>
+  <dt>Début le <dd><code>{{ vote.date_begin }}</code>
+  <dt>Fin le <dd><code>{{ vote.date_end }}</code>
+  <dt>Groupe <dd><code>{{ vote.rolename }}</code>
+  <dt>Catégorie <dd><code>{{ vote.category }}</code>
+</dl>
+<dl>
+  <dt>Description : <dd>{{ vote.description }}
+  <dt>Documents :<dd>
+  <ul>
+    {% for attachment in attachments %}
+    <li><a href="{{ attachment.url }}">{{ attachment.url }}</a></li>
+    {% endfor %}
+  </ul>
+  </li>
+</dl>
+</div>
+
 </div>
 {% endblock %}