mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Refactor elections
This commit is contained in:
parent
a284637190
commit
52e69b0ac1
@ -15,8 +15,7 @@ from club.models import Club, Membership
|
|||||||
from subscription.models import Subscription
|
from subscription.models import Subscription
|
||||||
from counter.models import Customer, ProductType, Product, Counter
|
from counter.models import Customer, ProductType, Product, Counter
|
||||||
from com.models import Sith
|
from com.models import Sith
|
||||||
from election.models import Election, Responsability, Candidate
|
from election.models import Election, Role, Candidature, List
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = "Populate a new instance of the Sith AE"
|
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()
|
operation.save()
|
||||||
|
|
||||||
# Create an election
|
# 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 = 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.save()
|
||||||
# resp = Responsability(election=el, title="Co Respo Info", description="Ghetto++")
|
liste = List(title="Candidature Libre", election=el)
|
||||||
# resp.save()
|
liste.save()
|
||||||
# cand = Candidate(responsability=resp, user=skia)
|
resp = Role(election=el, title="Co Respo Info", description="Ghetto++")
|
||||||
# cand.save()
|
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(
|
migrations.CreateModel(
|
||||||
name='Candidature',
|
name='Candidature',
|
||||||
fields=[
|
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)),
|
||||||
('program', models.TextField(blank=True, null=True, verbose_name='description')),
|
('program', models.TextField(null=True, verbose_name='description', blank=True)),
|
||||||
('has_voted', models.ManyToManyField(related_name='has_voted', to=settings.AUTH_USER_MODEL, verbose_name='has_voted')),
|
('has_voted', models.ManyToManyField(to=settings.AUTH_USER_MODEL, related_name='has_voted', verbose_name='has_voted')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Election',
|
name='Election',
|
||||||
fields=[
|
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')),
|
('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')),
|
('start_candidature', models.DateTimeField(verbose_name='start candidature')),
|
||||||
('end_candidature', models.DateTimeField(verbose_name='end candidature')),
|
('end_candidature', models.DateTimeField(verbose_name='end candidature')),
|
||||||
('start_date', models.DateTimeField(verbose_name='start date')),
|
('start_date', models.DateTimeField(verbose_name='start date')),
|
||||||
@ -35,35 +35,41 @@ class Migration(migrations.Migration):
|
|||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='List',
|
name='List',
|
||||||
fields=[
|
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')),
|
('title', models.CharField(max_length=255, verbose_name='title')),
|
||||||
|
('election', models.ForeignKey(to='election.Election', related_name='list', verbose_name='election')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Role',
|
name='Role',
|
||||||
fields=[
|
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')),
|
('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)),
|
||||||
('election', models.ForeignKey(related_name='role', to='election.Election', verbose_name='election')),
|
('election', models.ForeignKey(to='election.Election', related_name='role', verbose_name='election')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Vote',
|
name='Vote',
|
||||||
fields=[
|
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)),
|
||||||
('candidature', models.ManyToManyField(related_name='vote', to='election.Candidature', verbose_name='candidature')),
|
('candidature', models.ManyToManyField(to='election.Candidature', related_name='vote', verbose_name='candidature')),
|
||||||
('role', models.ForeignKey(related_name='vote', to='election.Role', verbose_name='role')),
|
('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(
|
migrations.AddField(
|
||||||
model_name='candidature',
|
model_name='candidature',
|
||||||
name='role',
|
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(
|
migrations.AddField(
|
||||||
model_name='candidature',
|
model_name='candidature',
|
||||||
name='user',
|
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)
|
return bool(now <= self.end_candidature and now >= self.start_candidature)
|
||||||
|
|
||||||
def has_voted(self, user):
|
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):
|
def get_results(self):
|
||||||
pass
|
pass
|
||||||
@ -50,6 +51,14 @@ class Role(models.Model):
|
|||||||
return ("%s : %s") % (self.election.title, self.title)
|
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):
|
class Candidature(models.Model):
|
||||||
"""
|
"""
|
||||||
This class is a component of responsability
|
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)
|
user = models.ForeignKey(User, verbose_name=_('user'), related_name='candidate', blank=True)
|
||||||
program = models.TextField(_('description'), null=True, blank=True)
|
program = models.TextField(_('description'), null=True, blank=True)
|
||||||
has_voted = models.ManyToManyField(User, verbose_name=_('has_voted'), related_name='has_voted')
|
has_voted = models.ManyToManyField(User, verbose_name=_('has_voted'), related_name='has_voted')
|
||||||
|
liste = models.ForeignKey(List, related_name='candidature', verbose_name=_('list'))
|
||||||
|
|
||||||
class List(models.Model):
|
|
||||||
"""
|
|
||||||
To allow per list vote
|
|
||||||
"""
|
|
||||||
title = models.CharField(_('title'), max_length=255)
|
|
||||||
|
|
||||||
|
|
||||||
class Vote(models.Model):
|
class Vote(models.Model):
|
||||||
|
@ -11,16 +11,16 @@
|
|||||||
<h1>{{object.title}}</h1>
|
<h1>{{object.title}}</h1>
|
||||||
<p>{{object.description}}</p>
|
<p>{{object.description}}</p>
|
||||||
<p>{% trans %}End :{% endtrans %} {{object.end_date}}</p>
|
<p>{% trans %}End :{% endtrans %} {{object.end_date}}</p>
|
||||||
{% for resp in object.responsability.all() %}
|
{% for role in object.role.all() %}
|
||||||
<h2>{{resp.title}}</h2>
|
<h2>{{role.title}}</h2>
|
||||||
{% for candidate in resp.candidate.all() %}
|
{% for candidature in role.candidature.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>
|
<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 candidate.user.profile_pict %}
|
{% if candidature.user.profile_pict %}
|
||||||
<img src="{{candidate.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}"/>
|
<p><img src="{{candidature.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}"/></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if candidate.program %}
|
{% if candidature.program %}
|
||||||
<h4>Programme</h4>
|
<h4>Programme</h4>
|
||||||
<p>{{candidate.program}}</p>
|
<p>{{candidature.program}}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -4,5 +4,5 @@ from election.views import *
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', ElectionsListView.as_view(), name='list'),
|
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'),
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user