diff --git a/election/migrations/0003_auto_20161205_2235.py b/election/migrations/0003_auto_20161205_2235.py new file mode 100644 index 00000000..e1d80308 --- /dev/null +++ b/election/migrations/0003_auto_20161205_2235.py @@ -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'), + ), + ] diff --git a/election/migrations/0004_election_electors.py b/election/migrations/0004_election_electors.py new file mode 100644 index 00000000..c1f932da --- /dev/null +++ b/election/migrations/0004_election_electors.py @@ -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'), + ), + ] diff --git a/election/models.py b/election/models.py index edd8cf09..3754f9b1 100644 --- a/election/models.py +++ b/election/models.py @@ -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) diff --git a/election/templates/election/election_detail.jinja b/election/templates/election/election_detail.jinja new file mode 100644 index 00000000..798f66dc --- /dev/null +++ b/election/templates/election/election_detail.jinja @@ -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 %} +

{{object.title}}

+

{{object.description}}

+

{% trans %}End :{% endtrans %} {{object.end_date}}

+ {% for resp in object.responsability.all() %} +

{{resp.title}}

+ {% for user in resp.candidate.all() %} +

{{user.subscriber.first_name}} {{user.subscriber.last_name}} ({{user.subscriber.nick_name}})

+ {% if user.subscriber.profile_pict %} + {% trans %}Profile{% endtrans %} + {% endif %} + {% if user.program %} +

Programme

+

{{user.program}}

+ {% endif %} + {% endfor %} + {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/election/templates/election/election_list.jinja b/election/templates/election/election_list.jinja index 2c10e9b9..77e4e1f9 100644 --- a/election/templates/election/election_list.jinja +++ b/election/templates/election/election_list.jinja @@ -7,7 +7,7 @@ {% block content %} {% for el in object_list %} {% if el.is_active %} -

{{el}}

+

{{el}}

{% endif %} {% endfor %} {% endblock %} \ No newline at end of file diff --git a/election/urls.py b/election/urls.py index ac646b59..5582fedd 100644 --- a/election/urls.py +++ b/election/urls.py @@ -3,5 +3,6 @@ from django.conf.urls import url, include from election.views import * urlpatterns = [ - url(r'^$', ElectionsListView.as_view(), name='election_list'), -] \ No newline at end of file + url(r'^$', ElectionsListView.as_view(), name='list'), + url(r'^/(?P[0-9]+)/detail$', ElectionDetailView.as_view(), name='detail'), +] diff --git a/election/views.py b/election/views.py index 91db1e73..2bcfcc10 100644 --- a/election/views.py +++ b/election/views.py @@ -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