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
e3711533
Commit
e3711533
authored
Jan 10, 2017
by
Sli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Less precise election results
parent
766d913a
Pipeline
#701
passed with stage
in 3 minutes and 16 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
9 deletions
+17
-9
election/models.py
election/models.py
+9
-5
election/templates/election/election_detail.jinja
election/templates/election/election_detail.jinja
+7
-3
election/views.py
election/views.py
+1
-1
No files found.
election/models.py
View file @
e3711533
...
...
@@ -85,18 +85,22 @@ class Role(models.Model):
def
results
(
self
,
total_vote
):
results
=
{}
total_vote
*=
self
.
max_choice
if
total_vote
==
0
:
return
None
non_blank
=
0
for
candidature
in
self
.
candidatures
.
all
():
cand_results
=
{}
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'
]
results
[
candidature
.
user
.
username
]
=
cand_results
results
[
'total vote'
]
=
total_vote
results
[
'blank vote'
]
=
{
'vote'
:
total_vote
-
non_blank
,
'percent'
:
(
total_vote
-
non_blank
)
*
100
/
total_vote
}
if
total_vote
==
0
:
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
@
property
...
...
election/templates/election/election_detail.jinja
View file @
e3711533
...
...
@@ -301,7 +301,7 @@ th {
{%
-
if
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>
<strong>
{{
results.vote
}}
{%
trans
%}
votes
{%
endtrans
%}
(
{{
"%.2f"
%
results.percent
}}
%)
</strong>
</div>
{%
-
endif
%}
</td>
...
...
@@ -318,12 +318,14 @@ th {
</div>
<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>
{%
-
if
not
election.is_vote_finished
%}
<q
class=
"candidate__program"
>
{{
candidature.program
or
''
}}
</q>
{%
-
endif
%}
{%
-
if
user.can_edit
(
candidature
)
-
%}
{%
if
election.is_vote_editable
%}
<a
href=
"
{{
url
(
'election:update_candidate'
,
candidature_id
=
candidature.id
)
}}
"
>
{%
trans
%}
Edit
{%
endtrans
%}
</a>
{%
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>
{%
-
endif
-
%}
{%
-
endif
-
%}
...
...
@@ -339,7 +341,7 @@ th {
{%
-
if
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>
<strong>
{{
results.vote
}}
{%
trans
%}
votes
{%
endtrans
%}
(
{{
"%.2f"
%
results.percent
}}
%)
</strong>
</div>
{%
-
endif
%}
</li>
...
...
@@ -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
)
%}
<a
href=
"
{{
url
(
'election:candidate'
,
election_id
=
object.id
)
}}
"
>
{%
trans
%}
Candidate
{%
endtrans
%}
</a>
{%
-
endif
%}
{%
-
if
election.is_vote_editable
%}
<a
href=
"
{{
url
(
'election:create_list'
,
election_id
=
object.id
)
}}
"
>
{%
trans
%}
Add a new list
{%
endtrans
%}
</a>
{%
-
endif
%}
{%
-
if
user.can_edit
(
election
)
%}
{%
if
election.is_vote_editable
%}
<a
href=
"
{{
url
(
'election:create_role'
,
election_id
=
object.id
)
}}
"
>
{%
trans
%}
Add a new role
{%
endtrans
%}
</a>
...
...
election/views.py
View file @
e3711533
...
...
@@ -472,7 +472,7 @@ class CandidatureDeleteView(CanEditMixin, DeleteView):
def
dispatch
(
self
,
request
,
*
arg
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
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
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