From 7956067686649777ae66c00d22384076710b5500 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Mon, 19 Dec 2016 20:30:19 +0100 Subject: [PATCH] Election right update --- core/management/commands/populate.py | 8 +++++ election/migrations/0002_role_max_choice.py | 19 ++++++++++ .../migrations/0003_auto_20161219_1832.py | 35 +++++++++++++++++++ election/models.py | 14 ++++---- 4 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 election/migrations/0002_role_max_choice.py create mode 100644 election/migrations/0003_auto_20161219_1832.py diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index 02110ad0..e69205c0 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -363,8 +363,16 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. operation.save() # Create an election + public_group = Group.objects.get(id=settings.SITH_GROUP_PUBLIC_ID) + subscriber_group = Group.objects.get(name=settings.SITH_MAIN_MEMBERS_GROUP) + ae_board_gorup = Group.objects.get(name=settings.SITH_MAIN_BOARD_GROUP) el = Election(title="Élection 2017", description="La roue tourne", start_candidature='1942-06-12 10:28:45', end_candidature='2042-06-12 10:28:45',start_date='1942-06-12 10:28:45', end_date='7942-06-12 10:28:45') el.save() + el.view_groups.add(public_group) + el.edit_groups.add(ae_board_gorup) + el.candidature_group.add(subscriber_group) + el.vote_group.add(subscriber_group) + el.save() liste = ElectionList(title="Candidature Libre", election=el) liste.save() listeT = ElectionList(title="Troll", election=el) diff --git a/election/migrations/0002_role_max_choice.py b/election/migrations/0002_role_max_choice.py new file mode 100644 index 00000000..ebce103d --- /dev/null +++ b/election/migrations/0002_role_max_choice.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('election', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='role', + name='max_choice', + field=models.IntegerField(verbose_name='max choice', default=1), + ), + ] diff --git a/election/migrations/0003_auto_20161219_1832.py b/election/migrations/0003_auto_20161219_1832.py new file mode 100644 index 00000000..55c03808 --- /dev/null +++ b/election/migrations/0003_auto_20161219_1832.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0016_auto_20161212_1922'), + ('election', '0002_role_max_choice'), + ] + + operations = [ + migrations.AddField( + model_name='election', + name='candidature_group', + field=models.ManyToManyField(related_name='candidate_election', blank=True, verbose_name='candidature group', to='core.Group'), + ), + migrations.AddField( + model_name='election', + name='edit_groups', + field=models.ManyToManyField(related_name='editable_election', blank=True, verbose_name='edit group', to='core.Group'), + ), + migrations.AddField( + model_name='election', + name='view_groups', + field=models.ManyToManyField(related_name='viewable_election', blank=True, verbose_name='view group', to='core.Group'), + ), + migrations.AddField( + model_name='election', + name='vote_group', + field=models.ManyToManyField(related_name='votable_election', blank=True, verbose_name='vote group', to='core.Group'), + ), + ] diff --git a/election/models.py b/election/models.py index 8e029bdf..7598e2a1 100644 --- a/election/models.py +++ b/election/models.py @@ -4,7 +4,7 @@ from django.utils import timezone from django.conf import settings from datetime import timedelta -from core.models import User +from core.models import User, Group class Election(models.Model): @@ -18,6 +18,11 @@ class Election(models.Model): start_date = models.DateTimeField(_('start date'), blank=False) end_date = models.DateTimeField(_('end date'), blank=False) + edit_groups = models.ManyToManyField(Group, related_name="editable_election", verbose_name=_("edit group"), blank=True) + view_groups = models.ManyToManyField(Group, related_name="viewable_election", verbose_name=_("view group"), blank=True) + vote_group = models.ManyToManyField(Group, related_name="votable_election", verbose_name=_("vote group"), blank=True) + candidature_group = models.ManyToManyField(Group, related_name="candidate_election", verbose_name=_("candidature group"), blank=True) + def __str__(self): return self.title @@ -38,11 +43,7 @@ class Election(models.Model): def get_results(self): pass - def can_view(self, obj): - return True - - def can_be_viewed_by(self, user): - return True + # Permissions class Role(models.Model): @@ -53,6 +54,7 @@ class Role(models.Model): 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') + max_choice = models.IntegerField(_('max choice'), default=1) def __str__(self): return ("%s : %s") % (self.election.title, self.title)