All: Apply Black coding rules

This commit is contained in:
2018-10-04 21:29:19 +02:00
parent 0581c667de
commit cb58b00b6e
204 changed files with 13173 additions and 6376 deletions

View File

@ -10,30 +10,45 @@ class Election(models.Model):
"""
This class allows to create a new election
"""
title = models.CharField(_('title'), max_length=255)
description = models.TextField(_('description'), null=True, blank=True)
start_candidature = models.DateTimeField(_('start candidature'), blank=False)
end_candidature = models.DateTimeField(_('end candidature'), blank=False)
start_date = models.DateTimeField(_('start date'), blank=False)
end_date = models.DateTimeField(_('end date'), blank=False)
title = models.CharField(_("title"), max_length=255)
description = models.TextField(_("description"), null=True, blank=True)
start_candidature = models.DateTimeField(_("start candidature"), blank=False)
end_candidature = models.DateTimeField(_("end candidature"), blank=False)
start_date = models.DateTimeField(_("start date"), blank=False)
end_date = models.DateTimeField(_("end date"), blank=False)
edit_groups = models.ManyToManyField(
Group, related_name="editable_elections",
verbose_name=_("edit groups"), blank=True)
Group,
related_name="editable_elections",
verbose_name=_("edit groups"),
blank=True,
)
view_groups = models.ManyToManyField(
Group, related_name="viewable_elections",
verbose_name=_("view groups"), blank=True)
Group,
related_name="viewable_elections",
verbose_name=_("view groups"),
blank=True,
)
vote_groups = models.ManyToManyField(
Group, related_name="votable_elections",
verbose_name=_("vote groups"), blank=True)
Group,
related_name="votable_elections",
verbose_name=_("vote groups"),
blank=True,
)
candidature_groups = models.ManyToManyField(
Group, related_name="candidate_elections",
verbose_name=_("candidature groups"), blank=True)
Group,
related_name="candidate_elections",
verbose_name=_("candidature groups"),
blank=True,
)
voters = models.ManyToManyField(User, verbose_name=('voters'), related_name='voted_elections')
voters = models.ManyToManyField(
User, verbose_name=("voters"), related_name="voted_elections"
)
archived = models.BooleanField(_("archived"), default=False)
def __str__(self):
@ -94,10 +109,13 @@ class Role(OrderedModel):
"""
This class allows to create a new role avaliable for a candidature
"""
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)
max_choice = models.IntegerField(_('max choice'), default=1)
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)
max_choice = models.IntegerField(_("max choice"), default=1)
def results(self, total_vote):
results = {}
@ -105,18 +123,21 @@ class Role(OrderedModel):
non_blank = 0
for candidature in self.candidatures.all():
cand_results = {}
cand_results['vote'] = self.votes.filter(candidature=candidature).count()
cand_results["vote"] = self.votes.filter(candidature=candidature).count()
if total_vote == 0:
cand_results['percent'] = 0
cand_results["percent"] = 0
else:
cand_results['percent'] = cand_results['vote'] * 100 / total_vote
non_blank += cand_results['vote']
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["total vote"] = total_vote
if total_vote == 0:
results['blank vote'] = {'vote': 0, 'percent': 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}
results["blank vote"] = {
"vote": total_vote - non_blank,
"percent": (total_vote - non_blank) * 100 / total_vote,
}
return results
@property
@ -131,8 +152,11 @@ class ElectionList(models.Model):
"""
To allow per list vote
"""
title = models.CharField(_('title'), max_length=255)
election = models.ForeignKey(Election, related_name='election_lists', verbose_name=_("election"))
title = models.CharField(_("title"), max_length=255)
election = models.ForeignKey(
Election, related_name="election_lists", verbose_name=_("election")
)
def can_be_edited_by(self, user):
return user.can_edit(self.election)
@ -150,10 +174,15 @@ class Candidature(models.Model):
"""
This class is a component of responsability
"""
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='candidatures', verbose_name=_('election list'))
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="candidatures", verbose_name=_("election list")
)
def delete(self):
for vote in self.votes.all():
@ -171,8 +200,11 @@ class Vote(models.Model):
"""
This class allows to vote for candidates
"""
role = models.ForeignKey(Role, related_name='votes', verbose_name=_("role"))
candidature = models.ManyToManyField(Candidature, related_name='votes', 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"