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 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()
|
||||
|
||||
|
@ -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'),
|
||||
),
|
||||
]
|
||||
|
@ -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):
|
||||
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):
|
||||
|
@ -13,8 +13,8 @@
|
||||
<p>{% trans %}End :{% endtrans %} {{object.end_date}}</p>
|
||||
<table>
|
||||
<tr>
|
||||
{% 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() %}
|
||||
<td>{{liste.title}}</td>
|
||||
{% set nb_list = nb_list + 1 -%}
|
||||
{% endfor %}
|
||||
@ -23,15 +23,18 @@
|
||||
{% for role in object.role.all() %}
|
||||
<tr><td colspan={{nb_list}}>{{role.title}}</td></tr>
|
||||
<tr>
|
||||
{% for liste in object.list.all() %}
|
||||
{% for liste in object.election_list.all() %}
|
||||
<td>
|
||||
<ul>
|
||||
{% for candidature in role.candidature.filter(liste=liste) %}
|
||||
{% for candidature in role.candidature.filter(election_list=liste) %}
|
||||
<li>
|
||||
{{candidature.user.first_name}} {{candidature.user.last_name}} {{candidature.user.nick_name or ''}}
|
||||
{% if candidature.user.profile_pict %}
|
||||
<br>
|
||||
<img src="{{candidature.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}">
|
||||
{% endif %}
|
||||
<br>
|
||||
{{candidature.program or ''}}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user