Commit 52e69b0a authored by Sli's avatar Sli

Refactor elections

parent a2846371
......@@ -15,8 +15,7 @@ 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, Responsability, Candidate
from election.models import Election, Role, Candidature, List
class Command(BaseCommand):
help = "Populate a new instance of the Sith AE"
......@@ -349,10 +348,12 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
operation.save()
# Create an election
# el = Election(title="Élection 2017", description="La roue tourne", start_proposal='1942-06-12 10:28:45', end_proposal='2042-06-12 10:28:45',start_date='1942-06-12 10:28:45', end_date='7942-06-12 10:28:45')
# el.save()
# resp = Responsability(election=el, title="Co Respo Info", description="Ghetto++")
# resp.save()
# cand = Candidate(responsability=resp, user=skia)
# cand.save()
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.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.save()
......@@ -15,17 +15,17 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Candidature',
fields=[
('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')),
('program', models.TextField(blank=True, null=True, verbose_name='description')),
('has_voted', models.ManyToManyField(related_name='has_voted', to=settings.AUTH_USER_MODEL, verbose_name='has_voted')),
('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')),
],
),
migrations.CreateModel(
name='Election',
fields=[
('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')),
('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(blank=True, null=True, verbose_name='description')),
('description', models.TextField(null=True, verbose_name='description', blank=True)),
('start_candidature', models.DateTimeField(verbose_name='start candidature')),
('end_candidature', models.DateTimeField(verbose_name='end candidature')),
('start_date', models.DateTimeField(verbose_name='start date')),
......@@ -35,35 +35,41 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='List',
fields=[
('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')),
('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')),
],
),
migrations.CreateModel(
name='Role',
fields=[
('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')),
('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(blank=True, null=True, verbose_name='description')),
('election', models.ForeignKey(related_name='role', to='election.Election', verbose_name='election')),
('description', models.TextField(null=True, verbose_name='description', blank=True)),
('election', models.ForeignKey(to='election.Election', related_name='role', verbose_name='election')),
],
),
migrations.CreateModel(
name='Vote',
fields=[
('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')),
('candidature', models.ManyToManyField(related_name='vote', to='election.Candidature', verbose_name='candidature')),
('role', models.ForeignKey(related_name='vote', to='election.Role', verbose_name='role')),
('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')),
],
),
migrations.AddField(
model_name='candidature',
name='liste',
field=models.ForeignKey(to='election.List', related_name='candidature', verbose_name='list'),
),
migrations.AddField(
model_name='candidature',
name='role',
field=models.ForeignKey(related_name='candidature', to='election.Role', verbose_name='role'),
field=models.ForeignKey(to='election.Role', related_name='candidature', verbose_name='role'),
),
migrations.AddField(
model_name='candidature',
name='user',
field=models.ForeignKey(blank=True, related_name='candidate', to=settings.AUTH_USER_MODEL, verbose_name='user'),
field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, related_name='candidate', verbose_name='user'),
),
]
......@@ -32,7 +32,8 @@ class Election(models.Model):
return bool(now <= self.end_candidature and now >= self.start_candidature)
def has_voted(self, user):
return self.has_voted.filter(id=user.id).exists()
return False
# return self.has_voted.filter(id=user.id).exists()
def get_results(self):
pass
......@@ -50,6 +51,14 @@ class Role(models.Model):
return ("%s : %s") % (self.election.title, self.title)
class List(models.Model):
"""
To allow per list vote
"""
title = models.CharField(_('title'), max_length=255)
election = models.ForeignKey(Election, related_name='list', verbose_name=_("election"))
class Candidature(models.Model):
"""
This class is a component of responsability
......@@ -58,13 +67,7 @@ class Candidature(models.Model):
user = models.ForeignKey(User, verbose_name=_('user'), related_name='candidate', blank=True)
program = models.TextField(_('description'), null=True, blank=True)
has_voted = models.ManyToManyField(User, verbose_name=_('has_voted'), related_name='has_voted')
class List(models.Model):
"""
To allow per list vote
"""
title = models.CharField(_('title'), max_length=255)
liste = models.ForeignKey(List, related_name='candidature', verbose_name=_('list'))
class Vote(models.Model):
......
......@@ -11,16 +11,16 @@
<h1>{{object.title}}</h1>
<p>{{object.description}}</p>
<p>{% trans %}End :{% endtrans %} {{object.end_date}}</p>
{% for resp in object.responsability.all() %}
<h2>{{resp.title}}</h2>
{% for candidate in resp.candidate.all() %}
<a href="{{url('core:user_profile', user_id=candidate.user.id)}}"><h3>{{candidate.user.first_name}} {{candidate.user.last_name}} ({{candidate.user.nick_name}})</h3></a>
{% if candidate.user.profile_pict %}
<img src="{{candidate.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}"/>
{% for role in object.role.all() %}
<h2>{{role.title}}</h2>
{% for candidature in role.candidature.all() %}
<a href="{{url('core:user_profile', user_id=candidature.user.id)}}"><h3>{{candidature.user.first_name}} {{candidature.user.last_name}} ({{candidature.user.nick_name}})</h3></a>
{% if candidature.user.profile_pict %}
<p><img src="{{candidature.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}"/></p>
{% endif %}
{% if candidate.program %}
{% if candidature.program %}
<h4>Programme</h4>
<p>{{candidate.program}}</p>
<p>{{candidature.program}}</p>
{% endif %}
{% endfor %}
{% endfor %}
......
......@@ -4,5 +4,5 @@ from election.views import *
urlpatterns = [
url(r'^$', ElectionsListView.as_view(), name='list'),
url(r'^/(?P<election_id>[0-9]+)/detail$', ElectionDetailView.as_view(), name='detail'),
url(r'^(?P<election_id>[0-9]+)/detail$', ElectionDetailView.as_view(), name='detail'),
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment