Bläddra i källkod

Improve templating

JoostSijm 6 år sedan
förälder
incheckning
2c978ee337

+ 1 - 1
app/modules/backend/templates/layout/backend.j2

@@ -7,7 +7,7 @@
 <body>
     <nav class="navbar navbar-expand-md navbar-dark bg-dark">
         <div class="container">
-            <a class="navbar-brand" href="/backend"><img src="/static/uploads/logo.png" style="height: 27px"></a>
+            <a class="navbar-brand" href="/backend"><img src="/static/uploads/logo.png" alt="DA" style="height: 27px"></a>
             <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsDefault" aria-controls="navbarsDefault" aria-expanded="false" aria-label="Toggle navigation">
                 <span class="navbar-toggler-icon"></span>
             </button>

+ 7 - 0
app/modules/backend/templates/layout/page.j2

@@ -0,0 +1,7 @@
+{% extends "layout/public.j2" %}
+{% block head %}
+<title>{{ page.title }} - Democratic Assembly</title>
+{% endblock %}
+{% block content %}
+{{ page.content() }}
+{% endblock %}

+ 4 - 4
app/modules/backend/templates/layout/public.j2

@@ -1,14 +1,14 @@
 <!DOCTYPE html>
-<html class="vh-100">
+<html class="vh-100" lang="nl">
 <head>
-    <title>{{ page.title }} - Democratic Assembly</title>
+    {% block head %}{% endblock %}
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <script src="/static/js/main.js"></script>
 </head>
 <body class="vh-100 background">
     <nav class="navbar row navbar-expand-lg navbar-dark bg-dark">
         <div class="container">
-            <a class="navbar-brand" href="/"><img src="/static/uploads/logo.png" style="height: 27px"></a>
+            <a class="navbar-brand" href="/"><img src="/static/uploads/logo.png" alt="DA" 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>
@@ -18,6 +18,6 @@
         </div>
     </nav>
     <div class="container p-3 bg-white min-vh-75">
-        {{ page.content() }}
+        {% block content %}{% endblock %}
     </div>
 </body>

+ 1 - 1
app/modules/backend/templates/public/private.j2

@@ -1,4 +1,4 @@
-{% extends "layout/public.j2" %}
+{% extends "layout/page.j2" %}
 {% block nav %}
 <ul class="navbar-nav mr-auto">
     {% for menu_item in menu %}

+ 1 - 1
app/modules/backend/templates/public/public.j2

@@ -1,4 +1,4 @@
-{% extends "layout/public.j2" %}
+{% extends "layout/page.j2" %}
 {% block nav %}
 <ul class="navbar-nav mr-auto">
     {% for menu_item in menu %}

+ 45 - 59
app/modules/vote/templates/vote/public/index.j2

@@ -1,59 +1,45 @@
-<!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>
-        <div class="table-responsive">
-            <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>
-    </div>
-</body>
+{% extends "layout/public.j2" %}
+{% block head %}
+<title>Votes - Democratic Assembly</title>
+{% endblock %}
+{% block content %}
+{% 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>
+<div class="table-responsive">
+    <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>
+{% endblock %}

+ 94 - 108
app/modules/vote/templates/vote/public/view.j2

@@ -1,115 +1,101 @@
-<!DOCTYPE html>
-<html>
-<head>
-    <title>{{ ballot.name }} - ssg</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 %}
+{% extends "layout/public.j2" %}
+{% block head %}
+<title>{{ ballot.name }} - Democratic Assembly</title>
+{% endblock %}
+{% block content %}
+{% 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>{{ ballot.name }}</h1>
+<table class="table table-sm">
+    {% if ballot.description %}
+    <tr>
+        <th scope="row">Description</th>
+        <td>{{ ballot.description }}</td>
+    </tr>
+    {% endif %}
+    <tr>
+        <th scope="row">Start</th>
+        <td>{{ ballot.start_at }}</td>
+    </tr>
+    <tr>
+        <th scope="row">Eindigt</th>
+        <td>{{ ballot.end_at }}</td>
+    </tr>
+    {% if ballot.active() %}
+    <tr>
+        <th scope="row">Te gaan</th>
+        <td class="countdown" date="{{ ballot.end_at }}"><span class="hours">00</span>:<span class="minutes">00</span>:<span class="seconds">00</span></td>
+    </tr>
+    {% endif %}
+    <tr>
+        <th scope="row">Aangemaakt door</th>
+        <td>{{ ballot.user.name }}</td>
+    </tr>
+    {% if ballot.priority %}
+    <tr>
+        <th scope="row">Priority</th>
+        <td>{{ ballot.priority.name }}</td>
+    </tr>
+    {% endif %}
+</table>
+{% if ballot.active() %}
+<form method="post">
+    <div class="card mb-4">
+        <div class="card-body">
+            <h5 class="card-title">Controle code</h5>
+            <input type="text" class="form-control" name="security_code" placeholder="code" required>
         </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>{{ ballot.name }}</h1>
-        <table class="table table-sm">
-            {% if ballot.description %}
-            <tr>
-                <th scope="row">Description</th>
-                <td>{{ ballot.description }}</td>
-            </tr>
-            {% endif %}
-            <tr>
-                <th scope="row">Start</th>
-                <td>{{ ballot.start_at }}</td>
-            </tr>
-            <tr>
-                <th scope="row">Eindigt</th>
-                <td>{{ ballot.end_at }}</td>
-            </tr>
-            {% if ballot.active() %}
-            <tr>
-                <th scope="row">Te gaan</th>
-                <td class="countdown" date="{{ ballot.end_at }}"><span class="hours">00</span>:<span class="minutes">00</span>:<span class="seconds">00</span></td>
-            </tr>
-            {% endif %}
-            <tr>
-                <th scope="row">Aangemaakt door</th>
-                <td>{{ ballot.user.name }}</td>
-            </tr>
-            {% if ballot.priority %}
-            <tr>
-                <th scope="row">Priority</th>
-                <td>{{ ballot.priority.name }}</td>
-            </tr>
+    </div>
+    {% for question in ballot.questions %}
+    <div class="card mb-4">
+        <div class="card-body">
+            <h5 class="card-title">{{ question.name }}</h5>
+            {% if question.description %}
+            <p class="card-text">{{ question.description }}</p>
             {% endif %}
-        </table>
-        {% if ballot.active() %}
-        <form method="post">
-            <div class="card mb-4">
-                <div class="card-body">
-                    <h5 class="card-title">Controle code</h5>
-                    <input type="text" class="form-control" name="security_code" placeholder="code" required>
-                </div>
-            </div>
-            {% for question in ballot.questions %}
-            <div class="card mb-4">
-                <div class="card-body">
-                    <h5 class="card-title">{{ question.name }}</h5>
-                    {% if question.description %}
-                    <p class="card-text">{{ question.description }}</p>
-                    {% endif %}
-                    {% for option in question.options %}
-                    <div class="form-check">
-                        <input class="form-check-input" type="radio" name="{{ question.id }}" id="{{ "option_%s" % option.id }}" value="{{ option.id }}">
-                        <label class="form-check-label" for="{{ "option_%s" % option.id }}">
-                            {{ option.name }}
-                        </label>
-                    </div>
-                    {% endfor %}
-                </div>
+            {% for option in question.options %}
+            <div class="form-check">
+                <input class="form-check-input" type="radio" name="{{ question.id }}" id="{{ "option_%s" % option.id }}" value="{{ option.id }}">
+                <label class="form-check-label" for="{{ "option_%s" % option.id }}">
+                    {{ option.name }}
+                </label>
             </div>
             {% endfor %}
-            <div class="form-group pull-right">
-                <button class="btn btn-primary" type="submit">Opslaan</button>
-            </div>
-        </form>
-        {% else %}
-        {% for question in ballot.questions %}
-        <div class="card mb-4">
-            <div class="card-body">
-                <h5 class="card-title">{{ question.name }}</h5>
-                {% if question.description %}
-                <p class="card-text">{{ question.description }}</p>
-                {% endif %}
-            </div>
-            <ul class="list-group list-group-flush">
-                {% for option in question.options %}
-                <li class="list-group-item d-flex justify-content-between align-items-center">
-                    {{ option.name }}
-                    <span class="badge badge-primary badge-pill">{{ option.votes.all() | count }}</span>
-                </li>
-                {% endfor %}
-            </ul>
         </div>
-        {% endfor %}
+    </div>
+    {% endfor %}
+    <div class="form-group pull-right">
+        <button class="btn btn-primary" type="submit">Opslaan</button>
+    </div>
+</form>
+{% else %}
+{% for question in ballot.questions %}
+<div class="card mb-4">
+    <div class="card-body">
+        <h5 class="card-title">{{ question.name }}</h5>
+        {% if question.description %}
+        <p class="card-text">{{ question.description }}</p>
         {% endif %}
     </div>
-</body>
+    <ul class="list-group list-group-flush">
+        {% for option in question.options %}
+        <li class="list-group-item d-flex justify-content-between align-items-center">
+            {{ option.name }}
+            <span class="badge badge-primary badge-pill">{{ option.votes.all() | count }}</span>
+        </li>
+        {% endfor %}
+    </ul>
+</div>
+{% endfor %}
+{% endif %}
+{% endblock %}