Nice display for elections

This commit is contained in:
Antoine Bartuccio 2016-12-19 03:54:57 +01:00
parent 52e69b0ac1
commit c604282b77
7 changed files with 92 additions and 15 deletions

View File

@ -318,6 +318,12 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
sli.save()
skia.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id]
sli.save()
# Adding user Krophil
krophil = User(username='krophil', last_name="Phil'", first_name="Kro",
email="krophil@git.an",
date_of_birth="1942-06-12")
krophil.set_password("plop")
krophil.save()
## Adding subscription for sli
s = Subscription(member=User.objects.filter(pk=sli.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
@ -326,6 +332,14 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'],
start=s.subscription_start)
s.save()
## Adding subscription for Krophil
s = Subscription(member=User.objects.filter(pk=krophil.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end(
duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'],
start=s.subscription_start)
s.save()
operation_list = [
(27, "J'avais trop de bière", 'CASH', None, buying, 'USER', skia.id, "", None),
@ -352,8 +366,18 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
el.save()
liste = List(title="Candidature Libre", election=el)
liste.save()
listeT = List(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.save()
cand = Candidature(role=resp, user=sli, liste=liste, program="Vasy je deviens mon propre adjoint")
cand.save()
cand = Candidature(role=resp, user=krophil, liste=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.save()

View File

@ -85,6 +85,12 @@
<li><a href="{{ url('club:tools', club_id=m.club.id) }}">{{ m.club }}</a></li>
{% endfor %}
</ul>
<hr>
<h4>{% trans %}Elections{% endtrans %}</h4>
<ul>
<li><a href="{{ url('election:list') }}">{% trans %}Vote{% endtrans %}</a></li>
<li><a href="">{% trans %}Candidate{% endtrans %}</a></li>
</ul>
{% endblock %}

View File

@ -0,0 +1,25 @@
# -*- 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'),
),
]

View File

@ -46,6 +46,7 @@ class Role(models.Model):
election = models.ForeignKey(Election, related_name='role', verbose_name=_("election"))
title = models.CharField(_('title'), max_length=255)
description = models.TextField(_('description'), null=True, blank=True)
has_voted = models.ManyToManyField(User, verbose_name=('has voted'), related_name='has_voted')
def __str__(self):
return ("%s : %s") % (self.election.title, self.title)
@ -66,7 +67,6 @@ 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)
has_voted = models.ManyToManyField(User, verbose_name=_('has_voted'), related_name='has_voted')
liste = models.ForeignKey(List, related_name='candidature', verbose_name=_('list'))

View File

@ -11,17 +11,34 @@
<h1>{{object.title}}</h1>
<p>{{object.description}}</p>
<p>{% trans %}End :{% endtrans %} {{object.end_date}}</p>
<table>
<tr>
{% set nb_list = object.list.all().count() + 1 -%}
{% for liste in object.list.all() %}
<td>{{liste.title}}</td>
{% set nb_list = nb_list + 1 -%}
{% endfor %}
<td>{% trans %}Blank vote{% endtrans %}</td>
</tr>
{% for role in object.role.all() %}
<h2>{{role.title}}</h2>
{% for candidature in role.candidature.all() %}
<a href="{{url('core:user_profile', user_id=candidature.user.id)}}"><h3>{{candidature.user.first_name}} {{candidature.user.last_name}} ({{candidature.user.nick_name}})</h3></a>
<tr><td colspan={{nb_list}}>{{role.title}}</td></tr>
<tr>
{% for liste in object.list.all() %}
<td>
<ul>
{% for candidature in role.candidature.filter(liste=liste) %}
<li>
{{candidature.user.first_name}} {{candidature.user.last_name}} {{candidature.user.nick_name or ''}}
{% if candidature.user.profile_pict %}
<p><img src="{{candidature.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}"/></p>
{% endif %}
{% if candidature.program %}
<h4>Programme</h4>
<p>{{candidature.program}}</p>
<img src="{{candidature.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}">
{% endif %}
</li>
{% endfor %}
</ul>
</td>
{% endfor %}
<td></td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -6,8 +6,6 @@
{% block content %}
{% for el in object_list %}
{% if el.is_active %}
<p><a href="{{ url('election:detail', election_id=el.id) }}">{{el}}</a></p>
{% endif %}
{% endfor %}
{% endblock %}

View File

@ -3,6 +3,7 @@ from django.views.generic import ListView, DetailView, RedirectView
from django.views.generic.edit import UpdateView, CreateView, DeleteView, FormView
from django.core.urlresolvers import reverse_lazy, reverse
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from django.conf import settings
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
@ -18,6 +19,12 @@ class ElectionsListView(CanViewMixin, ListView):
model = Election
template_name = 'election/election_list.jinja'
def get_queryset(self):
qs = super(ElectionsListView, self).get_queryset()
today = timezone.now()
qs = qs.filter(end_date__gte=today, start_date__lte=today)
return qs
class ElectionDetailView(CanViewMixin, DetailView):
"""