election_detail.jinja 10.1 KB
Newer Older
Sli's avatar
Sli committed
1
2
3
{% extends "core/base.jinja" %}

{% block title %}
4
{{object.title}}
Sli's avatar
Sli committed
5
6
{% endblock %}

7
8
9
{% block head %}
{{ super() -}}
<style type="text/css">
10
time {
11
    font-weight: bolder;
12
13
14
}

th {
15
16
17
18
19
20
21
    padding: 5px;
    margin: 5px;
    border: solid 1px darkgrey;
    border-collapse: collapse;
    vertical-align: top;
    overflow: hidden;
    text-overflow: ellipsis;
22
23
24
}

.election__title {
25
    margin: 0;
26
27
28
}

.election__description {
29
30
    margin: 0;
    margin-top: 5px;
31
32
33
}

.election__details {
34
35
    margin: 0;
    margin-bottom: 5px;
36
37
}

38
39
40
41
42
43
44
45
46
47
48
.election__elector-infos {
    margin: 0;
    margin-bottom: 5px;
    font-weight: bolder;
    color: darkgreen;
}

.election__vote {
    margin-bottom: 5px;
}

49
50
51
52
.election__vote-form {
    width: auto;
}

53
54
55
56
.role {

}

57
.role .role__title {
58
    background: lightgrey;
59
60
61
}

.role__multiple-choices {
62
    color: darkgreen;
63
64
}

65
66
67
68
.role__error {
    color: darkred;
}

69
.role .role_candidates {
70
    background: white;
71
72
}

73
.list-per-role {
74
75
    padding: 5px;
    max-width: 310px;
76
77
78
79

}

.list-per-role__candidates {
80
81
    list-style: none;
    margin: 0;
82
83
84
}

.list-per-role__candidate:not(:last-child) {
85
    margin-bottom: 5px;
86
87
88
}

.candidate {
89
90
    display: flex;
    flex-flow: row nowrap;
91
92
93
}

.candidate__picture-wrapper {
94
95
96
    display: flex;
    justify-content: center;
    align-items: center;
97

98
99
    width: 150px;
    height: 150px;
100
101
    min-width: 150px;
    min-height: 150px;
102

103
    background-color: lightgrey;
104
105
106
}

.candidate__picture {
107
108
    max-width: 150px;
    max-height: 150px;
109
110
111
}

.candidate__infos {
112
    margin-left: 5px;
113
114
115
}

.candidate__full-name {
116
    display: block;
117

118
    font-weight: bolder;
119
120
121
}

.candidate__nick-name {
122
    font-style: italic;
123
124
125
}

.candidate__program {
126
127
    display: block;
    margin-top: 5px;
128
129
130
}

.candidate__vote-input {
131
132
133
134
135
136
137
    position: absolute;
    border: 0;
    height: 1px;
    width: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
138
139
140
}

.candidate__vote-choice {
141
142
    margin-top: 5px;
    padding: 15px;
143

144
    border: solid 1px darkgrey;
145

146
147
148
    color: dimgray;
    text-align: center;
    font-weight: bolder;
149
150
}

151
152
.candidate__vote-input:not(:disabled:checked) + .candidate__vote-choice:hover,
.candidate__vote-input:not(:disabled:checked) + .candidate__vote-choice:focus {
153
    background: lightgrey;
154
}
155

156
.candidate__vote-input:checked + .candidate__vote-choice {
157
    padding: 14px;
158
159
160
    border-width: 2px;
    border-color: darkgreen;
    color: darkgreen;
161
162
}

163
164
165
166
167
168
.candidate__vote-input:not(:disabled) + .candidate__vote-choice {
    cursor: pointer;
}

.candidate__vote-input:checked:not(:disabled) + .candidate__vote-choice:hover,
.candidate__vote-input:checked:not(:disabled) + .candidate__vote-choice:focus {
169
    background: palegreen;
170
171
}

172
173
174
175
176
.role_error .candidate__vote-input:checked + .candidate__vote-choice {
    border-color: darkred;
    color: darkred;
}

177
178
.role_error .candidate__vote-input:checked:not(:disabled) + .candidate__vote-choice:hover,
.role_error .candidate__vote-input:checked:not(:disabled) + .candidate__vote-choice:focus {
179
180
181
    background: indianred;
}

182
.election__sumbit-section {
183
    margin-top: 5px;
184
185
186
}

.election__sumbit-button {
187
188
189
190
    display: block;
    width: 100%;
    padding: 20px;
    background: white;
191
    border: solid 15px #4081cb;
192
193
194
195
    text-align: center;
    font-size: 200%;
    font-weight: bolder;
    cursor: pointer;
196
}
197
198
199
200
201

.election__sumbit-button:hover,
.election__sumbit-button:focus {
    background-color: lightskyblue;
}
202
203
204
205
206
207
208
209
210
211
212
213

.election__add-elements a {
    display: inline-block;
    border: solid 1px darkgrey;
    height: 20px;
    line-height: 20px;
    padding: 10px;
}

.election__add-candidature {
    margin-top: 5px;
}
214
215
216
</style>
{%- endblock %}

Sli's avatar
Sli committed
217
{% block content %}
218
219
    <h3 class="election__title">{{ election.title }}</h3>
    <p class="election__description">{{ election.description }}</p>
220
221
222
223
224
225
    <hr>
    <section>
        <p class="election__details">
            {% trans %}Polls close {% endtrans %}
            <time datetime="{{ election.end_date }}">{{ election.end_date|date("l d F Y") }}</time> at <time>{{ election.end_date|time("G:i") }}</time>
        </p>
226
        {%- if election.has_voted(request.user) %}
227
228
229
230
        <p class="election__elector-infos">
            <span>{% trans %}You already have submitted your vote.{% endtrans %}</span>
        </p>
        {%- endif %}
231
    </section>
232
    <section class="election__vote">
233
234
235
236
237
238
239
        <form action="/election/1/vote" method="post" class="election__vote-form" name="vote-form" id="vote-form">
            {% csrf_token %}
            <table>
                {%- set election_lists = election.election_list.all() -%}
                <caption></caption>
                <thead>
                    <th>{% trans %}Blank vote{% endtrans %}</th>
240
                    {%- for election_list in election_lists %}
241
                    <th>{{election_list.title}}</th>
242
                    {%- endfor %}
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
                </thead>
                {%- for role in election.role.all() %}
                {%- set count = [0] %}
                {%- set role_data = election_form.data.getlist(role.title) if role.title in election_form.data else [] %}
                <tbody class="role {% if election_form.errors[role.title] is defined %}role_error{% endif %}">
                    <tr class="role__title">
                        <td colspan="{{election_lists.count() + 1}}">
                            <span>{{role.title}}</span>
                            {%- if role.max_choice > 1 %}
                            <strong class="role__multiple-choices">{% trans %}You may choose up to{% endtrans %} {{ role.max_choice }} {% trans %}people.{% endtrans %}</strong>
                            {%- endif %}
                            {%- if election_form.errors[role.title] is defined %}
                            {%- for error in election_form.errors.as_data()[role.title] %}
                            <strong class="role__error">{{ error.message }}</strong>
                            {%- endfor %}
                            {%- endif %}
                        </td>
                    </tr>
                    <tr class="role_candidates">
                        <td class="list-per-role">
                            {%- if election.is_active and role.max_choice == 1 %}
264
                            <input id="id_{{ role.title }}_{{ count[0] }}" class="candidate__vote-input" type="radio" name="{{ role.title }}" value {{ '' if role_data in election_form else 'checked' }} {{ 'disabled' if election.has_voted(request.user) else '' }}>
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
                            <label for="id_{{ role.title }}_{{ count[0] }}" class="candidate__vote-choice">
                                <span>{% trans %}Choose blank vote{% endtrans %}</span>
                            </label>
                            {%- set _ = count.append(count.pop() + 1) %}
                            {%- endif %}
                        </td>
                        {%- for election_list in election_lists %}
                        <td class="list-per-role">
                            <ul class="list-per-role__candidates">
                                {%- for candidature in election_list.candidature.filter(role=role) %}
                                <li class="list-per-role__candidate">
                                    <figure class="candidate">
                                        <div class="candidate__picture-wrapper">
                                            {%- if candidature.user.profile_pict %}
                                            <img class="candidate__picture" src="{{candidature.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}">
                                            {%- endif %}
                                        </div>
                                        <figcaption class="candidate__infos">
                                            <cite class="candidate__full-name">{{ candidature.user.first_name }} <em class="candidate__nick-name">{{candidature.user.nick_name or ''}} </em>{{ candidature.user.last_name }}</cite>
                                            <q class="candidate__program">{{ candidature.program or '' }}</q>
                                        </figcaption>
                                    </figure>
                                    {%- if election.is_active %}
288
                                    <input id="id_{{ role.title }}_{{ count[0] }}" type="{{ 'checkbox' if role.max_choice > 1 else 'radio' }}" {{ 'checked' if candidature.id|string in role_data else '' }} {{ 'disabled' if election.has_voted(request.user) else '' }} name="{{ role.title }}" value="{{ candidature.id }}" class="candidate__vote-input">
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
                                    <label for="id_{{ role.title }}_{{ count[0] }}" class="candidate__vote-choice">
                                        <span>{% trans %}Choose{% endtrans %} {{ candidature.user.nick_name or candidature.user.first_name }}</span>
                                    </label>
                                    {%- set _ = count.append(count.pop() + 1) %}
                                    {%- endif %}
                                </li>
                                {%- endfor %}
                            </ul>
                        </td>
                        {%- endfor %}
                    </tr>
                </tbody>
                {%- endfor %}
            </table>
        </form>
304
    </section>
305
    {%- if not election.has_voted(request.user) %}
306
    <section class="election__sumbit-section">
307
        <button class="election__sumbit-button" form="vote-form">{% trans %}Submit the vote !{% endtrans %}</button>
308
    </section>
309
310
    {%- endif %}
    {%- if request.user.can_edit(election) %}
311
312
313
314
    <section class="election__add-elements">
        <a href="{{url('election:create_list')}}">{% trans %}Add a new list{% endtrans %}</a>
        <a href="{{url('election:create_role')}}">{% trans %}Add a new role{% endtrans %}</a>
    </section>
315
316
317
318
319
320
321
322
323
    {%- endif %}
    {%- if election.can_candidate(request.user) %}
    <section class="election__add-candidature">
        <form action="{{url('election:candidate', election_id=election.id)}}" method="post">{{candidate_form}}
        {% csrf_token %}
        <p><input type="submit" value="{% trans %}Candidate{% endtrans %}" /></p>
        </form>
    </section>
    {%- endif %}
Sli's avatar
Sli committed
324
{% endblock %}