diff --git a/election/migrations/0005_auto_20161223_2240.py b/election/migrations/0005_auto_20161223_2240.py new file mode 100644 index 00000000..0538f465 --- /dev/null +++ b/election/migrations/0005_auto_20161223_2240.py @@ -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'), + ), + ] diff --git a/election/models.py b/election/models.py index 642129c3..9a0ff0f4 100644 --- a/election/models.py +++ b/election/models.py @@ -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.roles.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.roles.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='roles', 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.candidatures.all(): 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 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_lists', 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='candidatures', verbose_name=_("role")) + user = models.ForeignKey(User, verbose_name=_('user'), related_name='candidates', 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): 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='votes', verbose_name=_("role")) + candidature = models.ManyToManyField(Candidature, related_name='votes', verbose_name=_("candidature")) def __str__(self): return "Vote" \ No newline at end of file diff --git a/election/templates/election/election_detail.jinja b/election/templates/election/election_detail.jinja index 34f21dfb..2b86e546 100644 --- a/election/templates/election/election_detail.jinja +++ b/election/templates/election/election_detail.jinja @@ -258,7 +258,7 @@ th {
{% csrf_token %} - {%- set election_lists = election.election_list.all() -%} + {%- set election_lists = election.election_lists.all() -%} @@ -266,7 +266,7 @@ th { {%- endfor %} - {%- for role in election.role.all() %} + {%- for role in election.roles.all() %} {%- set count = [0] %} {%- set role_data = election_form.data.getlist(role.title) if role.title in election_form.data else [] %} @@ -302,7 +302,7 @@ th { {%- for election_list in election_lists %}
{% trans %}Blank vote{% endtrans %}{{election_list.title}}
    - {%- for candidature in election_list.candidature.filter(role=role) %} + {%- for candidature in election_list.candidatures.filter(role=role) %}
  • diff --git a/election/views.py b/election/views.py index 65bf437e..58220c89 100644 --- a/election/views.py +++ b/election/views.py @@ -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.roles.all(): if not role.user_has_voted(user): - cand = role.candidature + cand = role.candidatures 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.roles.get(title=role_title).has_voted.add(self.request.user) def get_form_kwargs(self): kwargs = super(VoteFormView, self).get_form_kwargs()