mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
Refactor election bdd
This commit is contained in:
parent
135fa00e25
commit
fd3309fc5f
@ -349,10 +349,10 @@ 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_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_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, subscriber=skia)
|
||||
cand = Candidate(responsability=resp, user=skia)
|
||||
cand.save()
|
||||
|
||||
|
@ -2,28 +2,31 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0003_auto_20160902_1914'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Candidate',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
|
||||
('votes', models.IntegerField(default=0, verbose_name='votes')),
|
||||
('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')),
|
||||
('program', models.TextField(blank=True, null=True, verbose_name='description')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Election',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
|
||||
('title', models.CharField(verbose_name='title', max_length=255)),
|
||||
('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=255, verbose_name='title')),
|
||||
('description', models.TextField(blank=True, null=True, verbose_name='description')),
|
||||
('start_proposal', models.DateTimeField(verbose_name='start proposal')),
|
||||
('end_proposal', models.DateTimeField(verbose_name='end proposal')),
|
||||
('start_date', models.DateTimeField(verbose_name='start date')),
|
||||
('end_date', models.DateTimeField(verbose_name='end date')),
|
||||
],
|
||||
@ -31,21 +34,29 @@ class Migration(migrations.Migration):
|
||||
migrations.CreateModel(
|
||||
name='Responsability',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
|
||||
('title', models.CharField(verbose_name='title', max_length=255)),
|
||||
('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=255, verbose_name='title')),
|
||||
('description', models.TextField(blank=True, null=True, verbose_name='description')),
|
||||
('blank_votes', models.IntegerField(default=0, verbose_name='blank votes')),
|
||||
('election', models.ForeignKey(to='election.Election', related_name='election', verbose_name='election')),
|
||||
('election', models.ForeignKey(to='election.Election', verbose_name='election', related_name='responsability')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Vote',
|
||||
fields=[
|
||||
('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')),
|
||||
('candidate', models.ManyToManyField(to='election.Candidate', related_name='vote', verbose_name='candidate')),
|
||||
('election', models.ForeignKey(to='election.Election', verbose_name='election', related_name='vote')),
|
||||
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, verbose_name='user', related_name='vote')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='candidate',
|
||||
name='responsability',
|
||||
field=models.ForeignKey(to='election.Responsability', related_name='responsability', verbose_name='responsability'),
|
||||
field=models.ForeignKey(to='election.Responsability', verbose_name='responsability', related_name='candidate'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='candidate',
|
||||
name='subscriber',
|
||||
field=models.ForeignKey(related_name='candidate', to='subscription.Subscriber', blank=True, verbose_name='user'),
|
||||
name='user',
|
||||
field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, verbose_name='user', related_name='candidate'),
|
||||
),
|
||||
]
|
||||
|
@ -1,19 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('election', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='candidate',
|
||||
name='program',
|
||||
field=models.TextField(verbose_name='description', null=True, blank=True),
|
||||
),
|
||||
]
|
@ -1,24 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('election', '0002_candidate_program'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='candidate',
|
||||
name='responsability',
|
||||
field=models.ForeignKey(verbose_name='responsability', to='election.Responsability', related_name='candidate'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='responsability',
|
||||
name='election',
|
||||
field=models.ForeignKey(verbose_name='election', to='election.Election', related_name='responsability'),
|
||||
),
|
||||
]
|
@ -1,20 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0003_auto_20160902_1914'),
|
||||
('election', '0003_auto_20161205_2235'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='election',
|
||||
name='electors',
|
||||
field=models.ManyToManyField(verbose_name='electors', related_name='election', blank=True, to='subscription.Subscriber'),
|
||||
),
|
||||
]
|
@ -11,13 +11,14 @@ from subscription.views import get_subscriber
|
||||
|
||||
class Election(models.Model):
|
||||
"""
|
||||
This class allow to create a new election
|
||||
This class allows to create a new election
|
||||
"""
|
||||
title = models.CharField(_('title'), max_length=255)
|
||||
description = models.TextField(_('description'), null=True, blank=True)
|
||||
start_proposal = models.DateTimeField(_('start proposal'), blank=False)
|
||||
end_proposal = models.DateTimeField(_('end proposal'), blank=False)
|
||||
start_date = models.DateTimeField(_('start date'), blank=False)
|
||||
end_date = models.DateTimeField(_('end date'), blank=False)
|
||||
electors = models.ManyToManyField(Subscriber, related_name='election', verbose_name=_("electors"), blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
@ -27,8 +28,13 @@ class Election(models.Model):
|
||||
now = timezone.now()
|
||||
return bool(now <= self.end_date and now >= self.start_date)
|
||||
|
||||
@property
|
||||
def is_proposal_active(self):
|
||||
now = timezone.now()
|
||||
return bool(now <= self.end_proposal and now >= self.start_proposal)
|
||||
|
||||
def has_voted(self, user):
|
||||
return self.electors.filter(id=user.id).exists()
|
||||
return self.vote.filter(user__id=user.id).exists()
|
||||
|
||||
def get_results(self):
|
||||
pass
|
||||
@ -36,11 +42,11 @@ class Election(models.Model):
|
||||
|
||||
class Responsability(models.Model):
|
||||
"""
|
||||
This class allows to create a new responsability
|
||||
"""
|
||||
election = models.ForeignKey(Election, related_name='responsability', verbose_name=_("election"))
|
||||
title = models.CharField(_('title'), max_length=255)
|
||||
description = models.TextField(_('description'), null=True, blank=True)
|
||||
blank_votes = models.IntegerField(_('blank votes'), default=0)
|
||||
|
||||
def __str__(self):
|
||||
return ("%s : %s") % (self.election.title, self.title)
|
||||
@ -48,11 +54,23 @@ class Responsability(models.Model):
|
||||
|
||||
class Candidate(models.Model):
|
||||
"""
|
||||
This class is a component of responsability
|
||||
"""
|
||||
responsability = models.ForeignKey(Responsability, related_name='candidate', verbose_name=_("responsability"))
|
||||
subscriber = models.ForeignKey(Subscriber, 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)
|
||||
votes = models.IntegerField(_('votes'), default=0)
|
||||
|
||||
def __str__(self):
|
||||
return ("%s : %s -> %s") % (self.election.title, self.title, self.subscriber.get_full_name())
|
||||
return ("%s : %s -> %s") % (self.election.title, self.title, self.user.get_full_name())
|
||||
|
||||
|
||||
class Vote(models.Model):
|
||||
"""
|
||||
This class allows to vote for candidates
|
||||
"""
|
||||
election = models.ForeignKey(Election, related_name='vote', verbose_name=_("election"))
|
||||
candidate = models.ManyToManyField(Candidate, related_name='vote', verbose_name=_("candidate"))
|
||||
user = models.ForeignKey(User, related_name='vote', verbose_name=_("user"))
|
||||
|
||||
def __str__(self):
|
||||
return "Vote"
|
@ -13,14 +13,14 @@
|
||||
<p>{% trans %}End :{% endtrans %} {{object.end_date}}</p>
|
||||
{% for resp in object.responsability.all() %}
|
||||
<h2>{{resp.title}}</h2>
|
||||
{% for user in resp.candidate.all() %}
|
||||
<a href="{{url('core:user_profile', user_id=user.subscriber.id)}}"><h3>{{user.subscriber.first_name}} {{user.subscriber.last_name}} ({{user.subscriber.nick_name}})</h3></a>
|
||||
{% if user.subscriber.profile_pict %}
|
||||
<img src="{{user.subscriber.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}"/>
|
||||
{% 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 %}"/>
|
||||
{% endif %}
|
||||
{% if user.program %}
|
||||
{% if candidate.program %}
|
||||
<h4>Programme</h4>
|
||||
<p>{{user.program}}</p>
|
||||
<p>{{candidate.program}}</p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue
Block a user