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
37decde0
Commit
37decde0
authored
Dec 23, 2016
by
Sli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds an S in electionS
parent
da77c188
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
17 deletions
+87
-17
election/migrations/0005_auto_20161223_2240.py
election/migrations/0005_auto_20161223_2240.py
+70
-0
election/models.py
election/models.py
+11
-11
election/templates/election/election_detail.jinja
election/templates/election/election_detail.jinja
+3
-3
election/views.py
election/views.py
+3
-3
No files found.
election/migrations/0005_auto_20161223_2240.py
0 → 100644
View file @
37decde0
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
from
django.conf
import
settings
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'election'
,
'0004_auto_20161219_2302'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'candidature'
,
name
=
'election_list'
,
field
=
models
.
ForeignKey
(
related_name
=
'candidatures'
,
to
=
'election.ElectionList'
,
verbose_name
=
'election_list'
),
),
migrations
.
AlterField
(
model_name
=
'candidature'
,
name
=
'role'
,
field
=
models
.
ForeignKey
(
related_name
=
'candidatures'
,
to
=
'election.Role'
,
verbose_name
=
'role'
),
),
migrations
.
AlterField
(
model_name
=
'candidature'
,
name
=
'user'
,
field
=
models
.
ForeignKey
(
verbose_name
=
'user'
,
to
=
settings
.
AUTH_USER_MODEL
,
related_name
=
'candidates'
,
blank
=
True
),
),
migrations
.
AlterField
(
model_name
=
'election'
,
name
=
'candidature_groups'
,
field
=
models
.
ManyToManyField
(
to
=
'core.Group'
,
related_name
=
'candidate_elections'
,
blank
=
True
,
verbose_name
=
'candidature groups'
),
),
migrations
.
AlterField
(
model_name
=
'election'
,
name
=
'edit_groups'
,
field
=
models
.
ManyToManyField
(
to
=
'core.Group'
,
related_name
=
'editable_elections'
,
blank
=
True
,
verbose_name
=
'edit groups'
),
),
migrations
.
AlterField
(
model_name
=
'election'
,
name
=
'view_groups'
,
field
=
models
.
ManyToManyField
(
to
=
'core.Group'
,
related_name
=
'viewable_elections'
,
blank
=
True
,
verbose_name
=
'view groups'
),
),
migrations
.
AlterField
(
model_name
=
'election'
,
name
=
'vote_groups'
,
field
=
models
.
ManyToManyField
(
to
=
'core.Group'
,
related_name
=
'votable_elections'
,
blank
=
True
,
verbose_name
=
'vote groups'
),
),
migrations
.
AlterField
(
model_name
=
'electionlist'
,
name
=
'election'
,
field
=
models
.
ForeignKey
(
related_name
=
'election_lists'
,
to
=
'election.Election'
,
verbose_name
=
'election'
),
),
migrations
.
AlterField
(
model_name
=
'role'
,
name
=
'election'
,
field
=
models
.
ForeignKey
(
related_name
=
'roles'
,
to
=
'election.Election'
,
verbose_name
=
'election'
),
),
migrations
.
AlterField
(
model_name
=
'vote'
,
name
=
'candidature'
,
field
=
models
.
ManyToManyField
(
to
=
'election.Candidature'
,
related_name
=
'votes'
,
verbose_name
=
'candidature'
),
),
migrations
.
AlterField
(
model_name
=
'vote'
,
name
=
'role'
,
field
=
models
.
ForeignKey
(
related_name
=
'votes'
,
to
=
'election.Role'
,
verbose_name
=
'role'
),
),
]
election/models.py
View file @
37decde0
...
...
@@ -41,7 +41,7 @@ class Election(models.Model):
return
bool
(
now
<=
self
.
end_candidature
and
now
>=
self
.
start_candidature
)
def
has_voted
(
self
,
user
):
for
role
in
self
.
role
.
all
():
for
role
in
self
.
role
s
.
all
():
if
role
.
user_has_voted
(
user
):
return
True
return
False
...
...
@@ -63,7 +63,7 @@ class Election(models.Model):
@
property
def
results
(
self
):
results
=
{}
for
role
in
self
.
role
.
all
():
for
role
in
self
.
role
s
.
all
():
results
[
role
.
title
]
=
role
.
results
return
results
...
...
@@ -74,7 +74,7 @@ class Role(models.Model):
"""
This class allows to create a new role avaliable for a candidature
"""
election
=
models
.
ForeignKey
(
Election
,
related_name
=
'role'
,
verbose_name
=
_
(
"election"
))
election
=
models
.
ForeignKey
(
Election
,
related_name
=
'role
s
'
,
verbose_name
=
_
(
"election"
))
title
=
models
.
CharField
(
_
(
'title'
),
max_length
=
255
)
description
=
models
.
TextField
(
_
(
'description'
),
null
=
True
,
blank
=
True
)
has_voted
=
models
.
ManyToManyField
(
User
,
verbose_name
=
(
'has voted'
),
related_name
=
'has_voted'
)
...
...
@@ -90,9 +90,9 @@ class Role(models.Model):
if
total_vote
==
0
:
return
None
non_blank
=
0
for
candidature
in
self
.
candidature
.
all
():
for
candidature
in
self
.
candidature
s
.
all
():
cand_results
=
{}
cand_results
[
'vote'
]
=
self
.
vote
.
filter
(
candidature
=
candidature
).
count
()
cand_results
[
'vote'
]
=
self
.
vote
s
.
filter
(
candidature
=
candidature
).
count
()
cand_results
[
'percent'
]
=
cand_results
[
'vote'
]
*
100
/
total_vote
non_blank
+=
cand_results
[
'vote'
]
results
[
candidature
.
user
.
username
]
=
cand_results
...
...
@@ -110,7 +110,7 @@ class ElectionList(models.Model):
To allow per list vote
"""
title
=
models
.
CharField
(
_
(
'title'
),
max_length
=
255
)
election
=
models
.
ForeignKey
(
Election
,
related_name
=
'election_list'
,
verbose_name
=
_
(
"election"
))
election
=
models
.
ForeignKey
(
Election
,
related_name
=
'election_list
s
'
,
verbose_name
=
_
(
"election"
))
def
__str__
(
self
):
return
self
.
title
...
...
@@ -120,10 +120,10 @@ class Candidature(models.Model):
"""
This class is a component of responsability
"""
role
=
models
.
ForeignKey
(
Role
,
related_name
=
'candidature'
,
verbose_name
=
_
(
"role"
))
user
=
models
.
ForeignKey
(
User
,
verbose_name
=
_
(
'user'
),
related_name
=
'candidate'
,
blank
=
True
)
role
=
models
.
ForeignKey
(
Role
,
related_name
=
'candidature
s
'
,
verbose_name
=
_
(
"role"
))
user
=
models
.
ForeignKey
(
User
,
verbose_name
=
_
(
'user'
),
related_name
=
'candidate
s
'
,
blank
=
True
)
program
=
models
.
TextField
(
_
(
'description'
),
null
=
True
,
blank
=
True
)
election_list
=
models
.
ForeignKey
(
ElectionList
,
related_name
=
'candidature'
,
verbose_name
=
_
(
'election_list'
))
election_list
=
models
.
ForeignKey
(
ElectionList
,
related_name
=
'candidature
s
'
,
verbose_name
=
_
(
'election_list'
))
def
__str__
(
self
):
return
"%s : %s"
%
(
self
.
role
.
title
,
self
.
user
.
username
)
...
...
@@ -133,8 +133,8 @@ class Vote(models.Model):
"""
This class allows to vote for candidates
"""
role
=
models
.
ForeignKey
(
Role
,
related_name
=
'vote'
,
verbose_name
=
_
(
"role"
))
candidature
=
models
.
ManyToManyField
(
Candidature
,
related_name
=
'vote'
,
verbose_name
=
_
(
"candidature"
))
role
=
models
.
ForeignKey
(
Role
,
related_name
=
'vote
s
'
,
verbose_name
=
_
(
"role"
))
candidature
=
models
.
ManyToManyField
(
Candidature
,
related_name
=
'vote
s
'
,
verbose_name
=
_
(
"candidature"
))
def
__str__
(
self
):
return
"Vote"
\ No newline at end of file
election/templates/election/election_detail.jinja
View file @
37decde0
...
...
@@ -258,7 +258,7 @@ th {
<form
action=
"
{{
url
(
'election:vote'
,
election.id
)
}}
"
method=
"post"
class=
"election__vote-form"
name=
"vote-form"
id=
"vote-form"
>
{%
csrf_token
%}
<table>
{%
-
set
election_lists
=
election.election_list.all
()
-
%}
{%
-
set
election_lists
=
election.election_list
s
.all
()
-
%}
<caption></caption>
<thead>
<th>
{%
trans
%}
Blank vote
{%
endtrans
%}
</th>
...
...
@@ -266,7 +266,7 @@ th {
<th>
{{
election_list.title
}}
</th>
{%
-
endfor
%}
</thead>
{%
-
for
role
in
election.role.all
()
%}
{%
-
for
role
in
election.role
s
.all
()
%}
{%
-
set
count
=
[
0
]
%}
{%
-
set
role_data
=
election_form.data.getlist
(
role.title
)
if
role.title
in
election_form.data
else
[]
%}
<tbody
data-max-choice=
"
{{
role.max_choice
}}
"
class=
"role
{{
' role_error'
if
role.title
in
election_form.errors
else
''
}}{{
' role__multiple-choices'
if
role.max_choice
>
1
else
''
}}
"
>
...
...
@@ -302,7 +302,7 @@ th {
{%
-
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
)
%}
{%
-
for
candidature
in
election_list.candidature
s
.
filter
(
role
=
role
)
%}
<li
class=
"list-per-role__candidate candidate"
>
<figure
class=
"candidate__infos"
>
<div
class=
"candidate__picture-wrapper"
>
...
...
election/views.py
View file @
37decde0
...
...
@@ -60,9 +60,9 @@ class CandidateForm(forms.Form):
class
VoteForm
(
forms
.
Form
):
def
__init__
(
self
,
election
,
user
,
*
args
,
**
kwargs
):
super
(
VoteForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
for
role
in
election
.
role
.
all
():
for
role
in
election
.
role
s
.
all
():
if
not
role
.
user_has_voted
(
user
):
cand
=
role
.
candidature
cand
=
role
.
candidature
s
if
role
.
max_choice
>
1
:
self
.
fields
[
role
.
title
]
=
VoteCheckbox
(
cand
,
role
.
max_choice
,
required
=
False
)
else
:
...
...
@@ -196,7 +196,7 @@ class VoteFormView(CanCreateMixin, FormView):
vote
=
Vote
(
role
=
election_data
[
role_title
].
role
)
vote
.
save
()
vote
.
candidature
.
add
(
election_data
[
role_title
])
self
.
election
.
role
.
get
(
title
=
role_title
).
has_voted
.
add
(
self
.
request
.
user
)
self
.
election
.
role
s
.
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