mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-18 04:03:22 +00:00
Refactor List Model
This commit is contained in:
parent
c604282b77
commit
2764f6d2d2
@ -15,7 +15,8 @@ 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, Role, Candidature, List
|
from election.models import Election, Role, Candidature, ElectionList
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = "Populate a new instance of the Sith AE"
|
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
|
# 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 = 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()
|
||||||
liste = List(title="Candidature Libre", election=el)
|
liste = ElectionList(title="Candidature Libre", election=el)
|
||||||
liste.save()
|
liste.save()
|
||||||
listeT = List(title="Troll", election=el)
|
listeT = ElectionList(title="Troll", election=el)
|
||||||
listeT.save()
|
listeT.save()
|
||||||
pres = Role(election=el, title="Président AE", description="Roi de l'AE")
|
pres = Role(election=el, title="Président AE", description="Roi de l'AE")
|
||||||
pres.save()
|
pres.save()
|
||||||
resp = Role(election=el, title="Co Respo Info", description="Ghetto++")
|
resp = Role(election=el, title="Co Respo Info", description="Ghetto++")
|
||||||
resp.save()
|
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.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.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.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()
|
cand.save()
|
||||||
|
|
||||||
|
@ -15,17 +15,16 @@ class Migration(migrations.Migration):
|
|||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Candidature',
|
name='Candidature',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
|
||||||
('program', models.TextField(null=True, verbose_name='description', blank=True)),
|
('program', models.TextField(blank=True, null=True, verbose_name='description')),
|
||||||
('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(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
|
||||||
('title', models.CharField(max_length=255, verbose_name='title')),
|
('title', models.CharField(verbose_name='title', max_length=255)),
|
||||||
('description', models.TextField(null=True, verbose_name='description', blank=True)),
|
('description', models.TextField(blank=True, null=True, verbose_name='description')),
|
||||||
('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')),
|
||||||
@ -33,43 +32,44 @@ class Migration(migrations.Migration):
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='List',
|
name='ElectionList',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
|
||||||
('title', models.CharField(max_length=255, verbose_name='title')),
|
('title', models.CharField(verbose_name='title', max_length=255)),
|
||||||
('election', models.ForeignKey(to='election.Election', related_name='list', verbose_name='election')),
|
('election', models.ForeignKey(related_name='election_list', verbose_name='election', to='election.Election')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Role',
|
name='Role',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
|
||||||
('title', models.CharField(max_length=255, verbose_name='title')),
|
('title', models.CharField(verbose_name='title', max_length=255)),
|
||||||
('description', models.TextField(null=True, verbose_name='description', blank=True)),
|
('description', models.TextField(blank=True, null=True, verbose_name='description')),
|
||||||
('election', models.ForeignKey(to='election.Election', related_name='role', verbose_name='election')),
|
('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(
|
migrations.CreateModel(
|
||||||
name='Vote',
|
name='Vote',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
|
||||||
('candidature', models.ManyToManyField(to='election.Candidature', related_name='vote', verbose_name='candidature')),
|
('candidature', models.ManyToManyField(related_name='vote', to='election.Candidature', verbose_name='candidature')),
|
||||||
('role', models.ForeignKey(to='election.Role', related_name='vote', verbose_name='role')),
|
('role', models.ForeignKey(related_name='vote', verbose_name='role', to='election.Role')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='candidature',
|
model_name='candidature',
|
||||||
name='liste',
|
name='election_list',
|
||||||
field=models.ForeignKey(to='election.List', related_name='candidature', verbose_name='list'),
|
field=models.ForeignKey(related_name='candidature', verbose_name='election_list', to='election.ElectionList'),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='candidature',
|
model_name='candidature',
|
||||||
name='role',
|
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(
|
migrations.AddField(
|
||||||
model_name='candidature',
|
model_name='candidature',
|
||||||
name='user',
|
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'),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -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'),
|
|
||||||
),
|
|
||||||
]
|
|
@ -38,6 +38,12 @@ class Election(models.Model):
|
|||||||
def get_results(self):
|
def get_results(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def can_view(self, obj):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def can_be_viewed_by(self, user):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Role(models.Model):
|
class Role(models.Model):
|
||||||
"""
|
"""
|
||||||
@ -52,12 +58,12 @@ class Role(models.Model):
|
|||||||
return ("%s : %s") % (self.election.title, self.title)
|
return ("%s : %s") % (self.election.title, self.title)
|
||||||
|
|
||||||
|
|
||||||
class List(models.Model):
|
class ElectionList(models.Model):
|
||||||
"""
|
"""
|
||||||
To allow per list vote
|
To allow per list vote
|
||||||
"""
|
"""
|
||||||
title = models.CharField(_('title'), max_length=255)
|
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):
|
class Candidature(models.Model):
|
||||||
@ -67,7 +73,7 @@ class Candidature(models.Model):
|
|||||||
role = models.ForeignKey(Role, related_name='candidature', verbose_name=_("role"))
|
role = models.ForeignKey(Role, related_name='candidature', verbose_name=_("role"))
|
||||||
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)
|
||||||
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):
|
class Vote(models.Model):
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
<p>{% trans %}End :{% endtrans %} {{object.end_date}}</p>
|
<p>{% trans %}End :{% endtrans %} {{object.end_date}}</p>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
{% set nb_list = object.list.all().count() + 1 -%}
|
{% set nb_list = object.election_list.all().count() + 1 -%}
|
||||||
{% for liste in object.list.all() %}
|
{% for liste in object.election_list.all() %}
|
||||||
<td>{{liste.title}}</td>
|
<td>{{liste.title}}</td>
|
||||||
{% set nb_list = nb_list + 1 -%}
|
{% set nb_list = nb_list + 1 -%}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -23,15 +23,18 @@
|
|||||||
{% for role in object.role.all() %}
|
{% for role in object.role.all() %}
|
||||||
<tr><td colspan={{nb_list}}>{{role.title}}</td></tr>
|
<tr><td colspan={{nb_list}}>{{role.title}}</td></tr>
|
||||||
<tr>
|
<tr>
|
||||||
{% for liste in object.list.all() %}
|
{% for liste in object.election_list.all() %}
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
{% for candidature in role.candidature.filter(liste=liste) %}
|
{% for candidature in role.candidature.filter(election_list=liste) %}
|
||||||
<li>
|
<li>
|
||||||
{{candidature.user.first_name}} {{candidature.user.last_name}} {{candidature.user.nick_name or ''}}
|
{{candidature.user.first_name}} {{candidature.user.last_name}} {{candidature.user.nick_name or ''}}
|
||||||
{% if candidature.user.profile_pict %}
|
{% if candidature.user.profile_pict %}
|
||||||
|
<br>
|
||||||
<img src="{{candidature.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}">
|
<img src="{{candidature.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<br>
|
||||||
|
{{candidature.program or ''}}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user