mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-15 18:53:25 +00:00
Fix database and add some view
This commit is contained in:
parent
d685e9ba29
commit
135fa00e25
24
election/migrations/0003_auto_20161205_2235.py
Normal file
24
election/migrations/0003_auto_20161205_2235.py
Normal file
@ -0,0 +1,24 @@
|
||||
# -*- 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'),
|
||||
),
|
||||
]
|
20
election/migrations/0004_election_electors.py
Normal file
20
election/migrations/0004_election_electors.py
Normal file
@ -0,0 +1,20 @@
|
||||
# -*- 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'),
|
||||
),
|
||||
]
|
@ -17,6 +17,7 @@ class Election(models.Model):
|
||||
description = models.TextField(_('description'), null=True, blank=True)
|
||||
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
|
||||
@ -26,6 +27,9 @@ class Election(models.Model):
|
||||
now = timezone.now()
|
||||
return bool(now <= self.end_date and now >= self.start_date)
|
||||
|
||||
def has_voted(self, user):
|
||||
return self.electors.filter(id=user.id).exists()
|
||||
|
||||
def get_results(self):
|
||||
pass
|
||||
|
||||
@ -33,7 +37,7 @@ class Election(models.Model):
|
||||
class Responsability(models.Model):
|
||||
"""
|
||||
"""
|
||||
election = models.ForeignKey(Election, related_name='election', verbose_name=_("election"))
|
||||
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)
|
||||
@ -45,7 +49,7 @@ class Responsability(models.Model):
|
||||
class Candidate(models.Model):
|
||||
"""
|
||||
"""
|
||||
responsability = models.ForeignKey(Responsability, related_name='responsability', verbose_name=_("responsability"))
|
||||
responsability = models.ForeignKey(Responsability, related_name='candidate', verbose_name=_("responsability"))
|
||||
subscriber = models.ForeignKey(Subscriber, verbose_name=_('user'), related_name='candidate', blank=True)
|
||||
program = models.TextField(_('description'), null=True, blank=True)
|
||||
votes = models.IntegerField(_('votes'), default=0)
|
||||
|
27
election/templates/election/election_detail.jinja
Normal file
27
election/templates/election/election_detail.jinja
Normal file
@ -0,0 +1,27 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Election list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if object.has_voted(request.user) %}
|
||||
A voté
|
||||
{% endif %}
|
||||
<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 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 %}"/>
|
||||
{% endif %}
|
||||
{% if user.program %}
|
||||
<h4>Programme</h4>
|
||||
<p>{{user.program}}</p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
@ -7,7 +7,7 @@
|
||||
{% block content %}
|
||||
{% for el in object_list %}
|
||||
{% if el.is_active %}
|
||||
<p>{{el}}</p>
|
||||
<p><a href="{{ url('election:detail', election_id=el.id) }}">{{el}}</a></p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
@ -3,5 +3,6 @@ from django.conf.urls import url, include
|
||||
from election.views import *
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', ElectionsListView.as_view(), name='election_list'),
|
||||
url(r'^$', ElectionsListView.as_view(), name='list'),
|
||||
url(r'^/(?P<election_id>[0-9]+)/detail$', ElectionDetailView.as_view(), name='detail'),
|
||||
]
|
@ -17,3 +17,14 @@ class ElectionsListView(CanViewMixin, ListView):
|
||||
"""
|
||||
model = Election
|
||||
template_name = 'election/election_list.jinja'
|
||||
|
||||
|
||||
class ElectionDetailView(CanViewMixin, DetailView):
|
||||
"""
|
||||
Details an election responsability by responsability
|
||||
"""
|
||||
model = Election
|
||||
template_name = 'election/election_detail.jinja'
|
||||
pk_url_kwarg = "election_id"
|
||||
|
||||
# Forms
|
||||
|
Loading…
Reference in New Issue
Block a user