Election right update

This commit is contained in:
Antoine Bartuccio 2016-12-19 20:30:19 +01:00
parent 2764f6d2d2
commit 7956067686
4 changed files with 70 additions and 6 deletions

View File

@ -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)

View File

@ -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),
),
]

View File

@ -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'),
),
]

View File

@ -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)