Jelajahi Sumber

Add public index page for votes

JoostSijm 6 tahun lalu
induk
melakukan
6015b4f234

+ 13 - 2
app/modules/vote/app.py

@@ -129,8 +129,19 @@ def add_question(ballot_id):
     )
 
 
+@BLUEPRINT.route('/public/')
+def public_index():
+    """View list of votes"""
+    ballots = Ballot.query.all()
+
+    return render_template(
+        'vote/public/index.j2',
+        ballots=ballots,
+    )
+
+
 @BLUEPRINT.route('/public/<int:ballot_id>', methods=["GET", "POST"])
-def public(ballot_id):
+def public_view(ballot_id):
     """Vote and view results of ballot"""
     ballot = Ballot.query.get(ballot_id)
 
@@ -164,6 +175,6 @@ def public(ballot_id):
             flash('Fout in veiligheids code.', 'warning')
 
     return render_template(
-        'vote/public.j2',
+        'vote/public/view.j2',
         ballot=ballot,
     )

+ 57 - 0
app/modules/vote/templates/vote/public/index.j2

@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title> Votes - Democratic Assembly</title>
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <script src="/static/js/main.js"></script>
+</head>
+<body>
+    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
+        <a class="navbar-brand" href="/"><img src="/static/uploads/logo.png" style="height: 27px"></a>
+        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
+            <span class="navbar-toggler-icon"></span>
+        </button>
+        <div class="collapse navbar-collapse" id="navbarSupportedContent">
+            {% block nav %}{% endblock %}
+        </div>
+    </nav>
+    <div class="container mt-3">
+        {% with messages = get_flashed_messages(with_categories=true) %}
+        {% if messages %}
+        {% for category, message in messages %}
+        <div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
+            {{ message }}
+            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
+                <span aria-hidden="true">&times;</span>
+            </button>
+        </div>
+        {% endfor %}
+        {% endif %}
+        {% endwith %}
+        <h1>Votes</h1>
+        <table class="table table-striped table-sm">
+            <thead>
+                <tr>
+                    <th></th>
+                    <th>Naam</th>
+                    <th>Start</th>
+                    <th>Eindigt</th>
+                    <th>Aangemaakt door</th>
+                </tr>
+            </thead>
+            <tbody>
+                {% for ballot in ballots %}
+                <tr>
+                    <td>
+                        <a href="{{ url_for('vote.public_view', ballot_id=ballot.id) }}"><button class="btn btn-secondary btn-sm">View</button></a>
+                    </td>
+                    <td>{{ ballot.name }}</td>
+                    <td>{{ ballot.start_at }}</td>
+                    <td>{{ ballot.end_at }}</td>
+                    <td>{{ ballot.user.name }}</td>
+                </tr>
+                {%- endfor -%}
+            </tbody>
+        </table>
+    </div>
+</body>

+ 0 - 0
app/modules/vote/templates/vote/public.j2 → app/modules/vote/templates/vote/public/view.j2