mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Adds an S in electionS
This commit is contained in:
parent
da77c18871
commit
37decde04d
70
election/migrations/0005_auto_20161223_2240.py
Normal file
70
election/migrations/0005_auto_20161223_2240.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
# -*- 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'),
|
||||||
|
),
|
||||||
|
]
|
@ -41,7 +41,7 @@ class Election(models.Model):
|
|||||||
return bool(now <= self.end_candidature and now >= self.start_candidature)
|
return bool(now <= self.end_candidature and now >= self.start_candidature)
|
||||||
|
|
||||||
def has_voted(self, user):
|
def has_voted(self, user):
|
||||||
for role in self.role.all():
|
for role in self.roles.all():
|
||||||
if role.user_has_voted(user):
|
if role.user_has_voted(user):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@ -63,7 +63,7 @@ class Election(models.Model):
|
|||||||
@property
|
@property
|
||||||
def results(self):
|
def results(self):
|
||||||
results = {}
|
results = {}
|
||||||
for role in self.role.all():
|
for role in self.roles.all():
|
||||||
results[role.title] = role.results
|
results[role.title] = role.results
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ class Role(models.Model):
|
|||||||
"""
|
"""
|
||||||
This class allows to create a new role avaliable for a candidature
|
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='roles', verbose_name=_("election"))
|
||||||
title = models.CharField(_('title'), max_length=255)
|
title = models.CharField(_('title'), max_length=255)
|
||||||
description = models.TextField(_('description'), null=True, blank=True)
|
description = models.TextField(_('description'), null=True, blank=True)
|
||||||
has_voted = models.ManyToManyField(User, verbose_name=('has voted'), related_name='has_voted')
|
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:
|
if total_vote == 0:
|
||||||
return None
|
return None
|
||||||
non_blank = 0
|
non_blank = 0
|
||||||
for candidature in self.candidature.all():
|
for candidature in self.candidatures.all():
|
||||||
cand_results = {}
|
cand_results = {}
|
||||||
cand_results['vote'] = self.vote.filter(candidature=candidature).count()
|
cand_results['vote'] = self.votes.filter(candidature=candidature).count()
|
||||||
cand_results['percent'] = cand_results['vote'] * 100 / total_vote
|
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
|
||||||
@ -110,7 +110,7 @@ class ElectionList(models.Model):
|
|||||||
To allow per list vote
|
To allow per list vote
|
||||||
"""
|
"""
|
||||||
title = models.CharField(_('title'), max_length=255)
|
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_lists', verbose_name=_("election"))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
@ -120,10 +120,10 @@ class Candidature(models.Model):
|
|||||||
"""
|
"""
|
||||||
This class is a component of responsability
|
This class is a component of responsability
|
||||||
"""
|
"""
|
||||||
role = models.ForeignKey(Role, related_name='candidature', verbose_name=_("role"))
|
role = models.ForeignKey(Role, related_name='candidatures', verbose_name=_("role"))
|
||||||
user = models.ForeignKey(User, verbose_name=_('user'), related_name='candidate', blank=True)
|
user = models.ForeignKey(User, verbose_name=_('user'), related_name='candidates', blank=True)
|
||||||
program = models.TextField(_('description'), null=True, 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='candidatures', verbose_name=_('election_list'))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s : %s" % (self.role.title, self.user.username)
|
return "%s : %s" % (self.role.title, self.user.username)
|
||||||
@ -133,8 +133,8 @@ class Vote(models.Model):
|
|||||||
"""
|
"""
|
||||||
This class allows to vote for candidates
|
This class allows to vote for candidates
|
||||||
"""
|
"""
|
||||||
role = models.ForeignKey(Role, related_name='vote', verbose_name=_("role"))
|
role = models.ForeignKey(Role, related_name='votes', verbose_name=_("role"))
|
||||||
candidature = models.ManyToManyField(Candidature, related_name='vote', verbose_name=_("candidature"))
|
candidature = models.ManyToManyField(Candidature, related_name='votes', verbose_name=_("candidature"))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Vote"
|
return "Vote"
|
@ -258,7 +258,7 @@ th {
|
|||||||
<form action="{{url('election:vote', election.id)}}" method="post" class="election__vote-form" name="vote-form" id="vote-form">
|
<form action="{{url('election:vote', election.id)}}" method="post" class="election__vote-form" name="vote-form" id="vote-form">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<table>
|
<table>
|
||||||
{%- set election_lists = election.election_list.all() -%}
|
{%- set election_lists = election.election_lists.all() -%}
|
||||||
<caption></caption>
|
<caption></caption>
|
||||||
<thead>
|
<thead>
|
||||||
<th>{% trans %}Blank vote{% endtrans %}</th>
|
<th>{% trans %}Blank vote{% endtrans %}</th>
|
||||||
@ -266,7 +266,7 @@ th {
|
|||||||
<th>{{election_list.title}}</th>
|
<th>{{election_list.title}}</th>
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
</thead>
|
</thead>
|
||||||
{%- for role in election.role.all() %}
|
{%- for role in election.roles.all() %}
|
||||||
{%- set count = [0] %}
|
{%- set count = [0] %}
|
||||||
{%- set role_data = election_form.data.getlist(role.title) if role.title in election_form.data else [] %}
|
{%- 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 ''}}">
|
<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 %}
|
{%- for election_list in election_lists %}
|
||||||
<td class="list-per-role">
|
<td class="list-per-role">
|
||||||
<ul class="list-per-role__candidates">
|
<ul class="list-per-role__candidates">
|
||||||
{%- for candidature in election_list.candidature.filter(role=role) %}
|
{%- for candidature in election_list.candidatures.filter(role=role) %}
|
||||||
<li class="list-per-role__candidate candidate">
|
<li class="list-per-role__candidate candidate">
|
||||||
<figure class="candidate__infos">
|
<figure class="candidate__infos">
|
||||||
<div class="candidate__picture-wrapper">
|
<div class="candidate__picture-wrapper">
|
||||||
|
@ -60,9 +60,9 @@ class CandidateForm(forms.Form):
|
|||||||
class VoteForm(forms.Form):
|
class VoteForm(forms.Form):
|
||||||
def __init__(self, election, user, *args, **kwargs):
|
def __init__(self, election, user, *args, **kwargs):
|
||||||
super(VoteForm, self).__init__(*args, **kwargs)
|
super(VoteForm, self).__init__(*args, **kwargs)
|
||||||
for role in election.role.all():
|
for role in election.roles.all():
|
||||||
if not role.user_has_voted(user):
|
if not role.user_has_voted(user):
|
||||||
cand = role.candidature
|
cand = role.candidatures
|
||||||
if role.max_choice > 1:
|
if role.max_choice > 1:
|
||||||
self.fields[role.title] = VoteCheckbox(cand, role.max_choice, required=False)
|
self.fields[role.title] = VoteCheckbox(cand, role.max_choice, required=False)
|
||||||
else:
|
else:
|
||||||
@ -196,7 +196,7 @@ class VoteFormView(CanCreateMixin, FormView):
|
|||||||
vote = Vote(role=election_data[role_title].role)
|
vote = Vote(role=election_data[role_title].role)
|
||||||
vote.save()
|
vote.save()
|
||||||
vote.candidature.add(election_data[role_title])
|
vote.candidature.add(election_data[role_title])
|
||||||
self.election.role.get(title=role_title).has_voted.add(self.request.user)
|
self.election.roles.get(title=role_title).has_voted.add(self.request.user)
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
kwargs = super(VoteFormView, self).get_form_kwargs()
|
kwargs = super(VoteFormView, self).get_form_kwargs()
|
||||||
|
Loading…
Reference in New Issue
Block a user