Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Sith
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
59
Issues
59
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AE
Sith
Commits
64f5fef8
Commit
64f5fef8
authored
Dec 23, 2016
by
Jean-Baptiste Lenglet
Committed by
Sli
Dec 25, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display results only when the polls close
parent
1c761f9d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
12 deletions
+21
-12
election/models.py
election/models.py
+4
-0
election/templates/election/election_detail.jinja
election/templates/election/election_detail.jinja
+5
-2
election/views.py
election/views.py
+12
-10
No files found.
election/models.py
View file @
64f5fef8
...
...
@@ -31,6 +31,10 @@ class Election(models.Model):
now
=
timezone
.
now
()
return
bool
(
now
<=
self
.
end_date
and
now
>=
self
.
start_date
)
@
property
def
is_vote_finished
(
self
):
return
bool
(
timezone
.
now
()
>
self
.
end_date
)
@
property
def
is_candidature_active
(
self
):
now
=
timezone
.
now
()
...
...
election/templates/election/election_detail.jinja
View file @
64f5fef8
...
...
@@ -235,6 +235,8 @@ th {
<p>
{%
-
if
election.is_vote_active
%}
{%
trans
%}
Polls close
{%
endtrans
%}
{%
-
elif
election.is_vote_finished
%}
{%
trans
%}
Polls closed
{%
endtrans
%}
{%
-
else
%}
{%
trans
%}
Polls will open
{%
endtrans
%}
<time
datetime=
"
{{
election.start_date
}}
"
>
{{
election.start_date
|
date
(
"l d F Y"
)
}}
</time>
at
<time>
{{
election.start_date
|
time
(
"G:i"
)
}}
</time>
...
...
@@ -290,7 +292,7 @@ th {
</label>
{%
-
set
_
=
count.append
(
count.pop
()
+
1
)
%}
{%
-
endif
%}
{%
-
if
election.has_voted
(
user
)
or
not
election.is_vote_active
%}
{%
-
if
not
election.is_vote_finished
%}
{%
-
set
results
=
election_results
[
role.title
][
'blank vote'
]
%}
<div
class=
"election__results"
>
<strong>
{{
results.vote
}}
{%
trans
%}
votes
{%
endtrans
%}
(
{{
results.percent
}}
%)
</strong>
...
...
@@ -319,7 +321,8 @@ th {
<span>
{%
trans
%}
Choose
{%
endtrans
%}
{{
candidature.user.nick_name
or
candidature.user.first_name
}}
</span>
</label>
{%
-
set
_
=
count.append
(
count.pop
()
+
1
)
%}
{%
-
else
%}
{%
-
endif
%}
{%
-
if
not
election.is_vote_finished
%}
{%
-
set
results
=
election_results
[
role.title
][
candidature.user.username
]
%}
<div
class=
"election__results"
>
<strong>
{{
results.vote
}}
{%
trans
%}
votes
{%
endtrans
%}
(
{{
results.percent
}}
%)
</strong>
...
...
election/views.py
View file @
64f5fef8
...
...
@@ -182,19 +182,21 @@ class VoteFormView(CanCreateMixin, FormView):
self
.
election
=
get_object_or_404
(
Election
,
pk
=
kwargs
[
'election_id'
])
return
super
(
VoteFormView
,
self
).
dispatch
(
request
,
*
arg
,
**
kwargs
)
def
vote
(
self
,
data
):
for
key
in
data
.
keys
():
if
isinstance
(
data
[
key
],
QuerySet
):
if
data
[
key
].
count
()
>
0
:
vote
=
Vote
(
role
=
data
[
key
].
first
().
role
)
def
vote
(
self
,
election_data
):
for
role_title
in
election_data
.
keys
():
# If we have a multiple choice field
if
isinstance
(
election_data
[
role_title
],
QuerySet
):
if
election_data
[
role_title
].
count
()
>
0
:
vote
=
Vote
(
role
=
election_data
[
role_title
].
first
().
role
)
vote
.
save
()
for
el
in
data
[
key
]:
for
el
in
election_data
[
role_title
]:
vote
.
candidature
.
add
(
el
)
elif
data
[
key
]
is
not
None
:
vote
=
Vote
(
role
=
data
[
key
].
role
)
# If we have a single choice
elif
election_data
[
role_title
]
is
not
None
:
vote
=
Vote
(
role
=
election_data
[
role_title
].
role
)
vote
.
save
()
vote
.
candidature
.
add
(
data
[
key
])
self
.
election
.
role
.
get
(
title
=
key
).
has_voted
.
add
(
self
.
request
.
user
)
vote
.
candidature
.
add
(
election_data
[
role_title
])
self
.
election
.
role
.
get
(
title
=
role_title
).
has_voted
.
add
(
self
.
request
.
user
)
def
get_form_kwargs
(
self
):
kwargs
=
super
(
VoteFormView
,
self
).
get_form_kwargs
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment