Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AE UTBM
Sith
Commits
3f6199f6
Commit
3f6199f6
authored
Jan 10, 2017
by
Skia
🤘
Browse files
Merge branch 'Elections' into 'master'
Less precise election results See merge request
!45
parents
766d913a
e3711533
Pipeline
#702
passed with stage
in 3 minutes and 17 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
election/models.py
View file @
3f6199f6
...
@@ -85,18 +85,22 @@ class Role(models.Model):
...
@@ -85,18 +85,22 @@ class Role(models.Model):
def
results
(
self
,
total_vote
):
def
results
(
self
,
total_vote
):
results
=
{}
results
=
{}
total_vote
*=
self
.
max_choice
total_vote
*=
self
.
max_choice
if
total_vote
==
0
:
return
None
non_blank
=
0
non_blank
=
0
for
candidature
in
self
.
candidatures
.
all
():
for
candidature
in
self
.
candidatures
.
all
():
cand_results
=
{}
cand_results
=
{}
cand_results
[
'vote'
]
=
self
.
votes
.
filter
(
candidature
=
candidature
).
count
()
cand_results
[
'vote'
]
=
self
.
votes
.
filter
(
candidature
=
candidature
).
count
()
cand_results
[
'percent'
]
=
cand_results
[
'vote'
]
*
100
/
total_vote
if
total_vote
==
0
:
cand_results
[
'percent'
]
=
0
else
:
cand_results
[
'percent'
]
=
cand_results
[
'vote'
]
*
100
/
total_vote
non_blank
+=
cand_results
[
'vote'
]
non_blank
+=
cand_results
[
'vote'
]
results
[
candidature
.
user
.
username
]
=
cand_results
results
[
candidature
.
user
.
username
]
=
cand_results
results
[
'total vote'
]
=
total_vote
results
[
'total vote'
]
=
total_vote
results
[
'blank vote'
]
=
{
'vote'
:
total_vote
-
non_blank
,
if
total_vote
==
0
:
'percent'
:
(
total_vote
-
non_blank
)
*
100
/
total_vote
}
results
[
'blank vote'
]
=
{
'vote'
:
0
,
'percent'
:
0
}
else
:
results
[
'blank vote'
]
=
{
'vote'
:
total_vote
-
non_blank
,
'percent'
:
(
total_vote
-
non_blank
)
*
100
/
total_vote
}
return
results
return
results
@
property
@
property
...
...
election/templates/election/election_detail.jinja
View file @
3f6199f6
...
@@ -301,7 +301,7 @@ th {
...
@@ -301,7 +301,7 @@ th {
{%
-
if
election.is_vote_finished
%}
{%
-
if
election.is_vote_finished
%}
{%
-
set
results
=
election_results
[
role.title
][
'blank vote'
]
%}
{%
-
set
results
=
election_results
[
role.title
][
'blank vote'
]
%}
<div
class=
"election__results"
>
<div
class=
"election__results"
>
<strong>
{{
results.vote
}}
{%
trans
%}
votes
{%
endtrans
%}
(
{{
results.percent
}}
%)
</strong>
<strong>
{{
results.vote
}}
{%
trans
%}
votes
{%
endtrans
%}
(
{{
"%.2f"
%
results.percent
}}
%)
</strong>
</div>
</div>
{%
-
endif
%}
{%
-
endif
%}
</td>
</td>
...
@@ -318,12 +318,14 @@ th {
...
@@ -318,12 +318,14 @@ th {
</div>
</div>
<figcaption
class=
"candidate__details"
>
<figcaption
class=
"candidate__details"
>
<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>
<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>
{%
-
if
not
election.is_vote_finished
%}
<q
class=
"candidate__program"
>
{{
candidature.program
or
''
}}
</q>
<q
class=
"candidate__program"
>
{{
candidature.program
or
''
}}
</q>
{%
-
endif
%}
{%
-
if
user.can_edit
(
candidature
)
-
%}
{%
-
if
user.can_edit
(
candidature
)
-
%}
{%
if
election.is_vote_editable
%}
{%
if
election.is_vote_editable
%}
<a
href=
"
{{
url
(
'election:update_candidate'
,
candidature_id
=
candidature.id
)
}}
"
>
{%
trans
%}
Edit
{%
endtrans
%}
</a>
<a
href=
"
{{
url
(
'election:update_candidate'
,
candidature_id
=
candidature.id
)
}}
"
>
{%
trans
%}
Edit
{%
endtrans
%}
</a>
{%
endif
%}
{%
endif
%}
{%
if
election.
can_candidat
e
-
%}
{%
if
election.
is_vote_editabl
e
-
%}
<a
href=
"
{{
url
(
'election:delete_candidate'
,
candidature_id
=
candidature.id
)
}}
"
>
{%
trans
%}
Delete
{%
endtrans
%}
</a>
<a
href=
"
{{
url
(
'election:delete_candidate'
,
candidature_id
=
candidature.id
)
}}
"
>
{%
trans
%}
Delete
{%
endtrans
%}
</a>
{%
-
endif
-
%}
{%
-
endif
-
%}
{%
-
endif
-
%}
{%
-
endif
-
%}
...
@@ -339,7 +341,7 @@ th {
...
@@ -339,7 +341,7 @@ th {
{%
-
if
election.is_vote_finished
%}
{%
-
if
election.is_vote_finished
%}
{%
-
set
results
=
election_results
[
role.title
][
candidature.user.username
]
%}
{%
-
set
results
=
election_results
[
role.title
][
candidature.user.username
]
%}
<div
class=
"election__results"
>
<div
class=
"election__results"
>
<strong>
{{
results.vote
}}
{%
trans
%}
votes
{%
endtrans
%}
(
{{
results.percent
}}
%)
</strong>
<strong>
{{
results.vote
}}
{%
trans
%}
votes
{%
endtrans
%}
(
{{
"%.2f"
%
results.percent
}}
%)
</strong>
</div>
</div>
{%
-
endif
%}
{%
-
endif
%}
</li>
</li>
...
@@ -362,7 +364,9 @@ th {
...
@@ -362,7 +364,9 @@ th {
{%
-
if
(
election.can_candidate
(
user
)
and
election.is_candidature_active
)
or
(
user.can_edit
(
election
)
and
election.is_vote_editable
)
%}
{%
-
if
(
election.can_candidate
(
user
)
and
election.is_candidature_active
)
or
(
user.can_edit
(
election
)
and
election.is_vote_editable
)
%}
<a
href=
"
{{
url
(
'election:candidate'
,
election_id
=
object.id
)
}}
"
>
{%
trans
%}
Candidate
{%
endtrans
%}
</a>
<a
href=
"
{{
url
(
'election:candidate'
,
election_id
=
object.id
)
}}
"
>
{%
trans
%}
Candidate
{%
endtrans
%}
</a>
{%
-
endif
%}
{%
-
endif
%}
{%
-
if
election.is_vote_editable
%}
<a
href=
"
{{
url
(
'election:create_list'
,
election_id
=
object.id
)
}}
"
>
{%
trans
%}
Add a new list
{%
endtrans
%}
</a>
<a
href=
"
{{
url
(
'election:create_list'
,
election_id
=
object.id
)
}}
"
>
{%
trans
%}
Add a new list
{%
endtrans
%}
</a>
{%
-
endif
%}
{%
-
if
user.can_edit
(
election
)
%}
{%
-
if
user.can_edit
(
election
)
%}
{%
if
election.is_vote_editable
%}
{%
if
election.is_vote_editable
%}
<a
href=
"
{{
url
(
'election:create_role'
,
election_id
=
object.id
)
}}
"
>
{%
trans
%}
Add a new role
{%
endtrans
%}
</a>
<a
href=
"
{{
url
(
'election:create_role'
,
election_id
=
object.id
)
}}
"
>
{%
trans
%}
Add a new role
{%
endtrans
%}
</a>
...
...
election/views.py
View file @
3f6199f6
...
@@ -472,7 +472,7 @@ class CandidatureDeleteView(CanEditMixin, DeleteView):
...
@@ -472,7 +472,7 @@ class CandidatureDeleteView(CanEditMixin, DeleteView):
def
dispatch
(
self
,
request
,
*
arg
,
**
kwargs
):
def
dispatch
(
self
,
request
,
*
arg
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
self
.
object
=
self
.
get_object
()
self
.
election
=
self
.
object
.
role
.
election
self
.
election
=
self
.
object
.
role
.
election
if
not
self
.
election
.
can_candidate
:
if
not
self
.
election
.
can_candidate
or
not
self
.
election
.
is_vote_editable
:
raise
PermissionDenied
raise
PermissionDenied
return
super
(
CandidatureDeleteView
,
self
).
dispatch
(
request
,
*
arg
,
**
kwargs
)
return
super
(
CandidatureDeleteView
,
self
).
dispatch
(
request
,
*
arg
,
**
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