diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index 2bdd2e46..02110ad0 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -15,7 +15,8 @@ from club.models import Club, Membership from subscription.models import Subscription from counter.models import Customer, ProductType, Product, Counter from com.models import Sith -from election.models import Election, Role, Candidature, List +from election.models import Election, Role, Candidature, ElectionList + class Command(BaseCommand): help = "Populate a new instance of the Sith AE" @@ -364,20 +365,20 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. # Create an election 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() - liste = List(title="Candidature Libre", election=el) + liste = ElectionList(title="Candidature Libre", election=el) liste.save() - listeT = List(title="Troll", election=el) + listeT = ElectionList(title="Troll", election=el) listeT.save() pres = Role(election=el, title="Président AE", description="Roi de l'AE") pres.save() resp = Role(election=el, title="Co Respo Info", description="Ghetto++") resp.save() - cand = Candidature(role=resp, user=skia, liste=liste, program="Refesons le site AE") + cand = Candidature(role=resp, user=skia, election_list=liste, program="Refesons le site AE") cand.save() - cand = Candidature(role=resp, user=sli, liste=liste, program="Vasy je deviens mon propre adjoint") + cand = Candidature(role=resp, user=sli, election_list=liste, program="Vasy je deviens mon propre adjoint") cand.save() - cand = Candidature(role=resp, user=krophil, liste=listeT, program="Le Pôle Troll !") + cand = Candidature(role=resp, user=krophil, election_list=listeT, program="Le Pôle Troll !") cand.save() - cand = Candidature(role=pres, user=sli, liste=listeT, program="En fait j'aime pas l'info, je voulais faire GMC") + cand = Candidature(role=pres, user=sli, election_list=listeT, program="En fait j'aime pas l'info, je voulais faire GMC") cand.save() diff --git a/election/migrations/0001_initial.py b/election/migrations/0001_initial.py index f533d513..bb784252 100644 --- a/election/migrations/0001_initial.py +++ b/election/migrations/0001_initial.py @@ -15,17 +15,16 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Candidature', fields=[ - ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), - ('program', models.TextField(null=True, verbose_name='description', blank=True)), - ('has_voted', models.ManyToManyField(to=settings.AUTH_USER_MODEL, related_name='has_voted', verbose_name='has_voted')), + ('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)), + ('program', models.TextField(blank=True, null=True, verbose_name='description')), ], ), migrations.CreateModel( name='Election', fields=[ - ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), - ('title', models.CharField(max_length=255, verbose_name='title')), - ('description', models.TextField(null=True, verbose_name='description', blank=True)), + ('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)), + ('title', models.CharField(verbose_name='title', max_length=255)), + ('description', models.TextField(blank=True, null=True, verbose_name='description')), ('start_candidature', models.DateTimeField(verbose_name='start candidature')), ('end_candidature', models.DateTimeField(verbose_name='end candidature')), ('start_date', models.DateTimeField(verbose_name='start date')), @@ -33,43 +32,44 @@ class Migration(migrations.Migration): ], ), migrations.CreateModel( - name='List', + name='ElectionList', fields=[ - ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), - ('title', models.CharField(max_length=255, verbose_name='title')), - ('election', models.ForeignKey(to='election.Election', related_name='list', verbose_name='election')), + ('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)), + ('title', models.CharField(verbose_name='title', max_length=255)), + ('election', models.ForeignKey(related_name='election_list', verbose_name='election', to='election.Election')), ], ), migrations.CreateModel( name='Role', fields=[ - ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), - ('title', models.CharField(max_length=255, verbose_name='title')), - ('description', models.TextField(null=True, verbose_name='description', blank=True)), - ('election', models.ForeignKey(to='election.Election', related_name='role', verbose_name='election')), + ('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)), + ('title', models.CharField(verbose_name='title', max_length=255)), + ('description', models.TextField(blank=True, null=True, verbose_name='description')), + ('election', models.ForeignKey(related_name='role', verbose_name='election', to='election.Election')), + ('has_voted', models.ManyToManyField(related_name='has_voted', to=settings.AUTH_USER_MODEL, verbose_name='has voted')), ], ), migrations.CreateModel( name='Vote', fields=[ - ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), - ('candidature', models.ManyToManyField(to='election.Candidature', related_name='vote', verbose_name='candidature')), - ('role', models.ForeignKey(to='election.Role', related_name='vote', verbose_name='role')), + ('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)), + ('candidature', models.ManyToManyField(related_name='vote', to='election.Candidature', verbose_name='candidature')), + ('role', models.ForeignKey(related_name='vote', verbose_name='role', to='election.Role')), ], ), migrations.AddField( model_name='candidature', - name='liste', - field=models.ForeignKey(to='election.List', related_name='candidature', verbose_name='list'), + name='election_list', + field=models.ForeignKey(related_name='candidature', verbose_name='election_list', to='election.ElectionList'), ), migrations.AddField( model_name='candidature', name='role', - field=models.ForeignKey(to='election.Role', related_name='candidature', verbose_name='role'), + field=models.ForeignKey(related_name='candidature', verbose_name='role', to='election.Role'), ), migrations.AddField( model_name='candidature', name='user', - field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, related_name='candidate', verbose_name='user'), + field=models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='candidate', blank=True, verbose_name='user'), ), ] diff --git a/election/migrations/0002_auto_20161219_0002.py b/election/migrations/0002_auto_20161219_0002.py deleted file mode 100644 index 5db7619c..00000000 --- a/election/migrations/0002_auto_20161219_0002.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models -from django.conf import settings - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('election', '0001_initial'), - ] - - operations = [ - migrations.RemoveField( - model_name='candidature', - name='has_voted', - ), - migrations.AddField( - model_name='role', - name='has_voted', - field=models.ManyToManyField(to=settings.AUTH_USER_MODEL, related_name='has_voted', verbose_name='has voted'), - ), - ] diff --git a/election/models.py b/election/models.py index 5a3e5da7..8e029bdf 100644 --- a/election/models.py +++ b/election/models.py @@ -38,6 +38,12 @@ 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 + class Role(models.Model): """ @@ -52,12 +58,12 @@ class Role(models.Model): return ("%s : %s") % (self.election.title, self.title) -class List(models.Model): +class ElectionList(models.Model): """ To allow per list vote """ title = models.CharField(_('title'), max_length=255) - election = models.ForeignKey(Election, related_name='list', verbose_name=_("election")) + election = models.ForeignKey(Election, related_name='election_list', verbose_name=_("election")) class Candidature(models.Model): @@ -67,7 +73,7 @@ class Candidature(models.Model): role = models.ForeignKey(Role, related_name='candidature', verbose_name=_("role")) user = models.ForeignKey(User, verbose_name=_('user'), related_name='candidate', blank=True) program = models.TextField(_('description'), null=True, blank=True) - liste = models.ForeignKey(List, related_name='candidature', verbose_name=_('list')) + election_list = models.ForeignKey(ElectionList, related_name='candidature', verbose_name=_('election_list')) class Vote(models.Model): diff --git a/election/templates/election/election_detail.jinja b/election/templates/election/election_detail.jinja index 55e6603d..d48866eb 100644 --- a/election/templates/election/election_detail.jinja +++ b/election/templates/election/election_detail.jinja @@ -13,8 +13,8 @@

{% trans %}End :{% endtrans %} {{object.end_date}}

- {% set nb_list = object.list.all().count() + 1 -%} - {% for liste in object.list.all() %} + {% set nb_list = object.election_list.all().count() + 1 -%} + {% for liste in object.election_list.all() %} {% set nb_list = nb_list + 1 -%} {% endfor %} @@ -23,15 +23,18 @@ {% for role in object.role.all() %} - {% for liste in object.list.all() %} + {% for liste in object.election_list.all() %}
{{liste.title}}
{{role.title}}
    - {% for candidature in role.candidature.filter(liste=liste) %} + {% for candidature in role.candidature.filter(election_list=liste) %}
  • {{candidature.user.first_name}} {{candidature.user.last_name}} {{candidature.user.nick_name or ''}} {% if candidature.user.profile_pict %} +
    {% trans %}Profile{% endtrans %} {% endif %} +
    + {{candidature.program or ''}}
  • {% endfor %}