Sith/election/views.py

38 lines
1.1 KiB
Python
Raw Normal View History

2016-12-05 19:18:03 +00:00
from django.shortcuts import render
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 _
2016-12-19 02:54:57 +00:00
from django.utils import timezone
2016-12-05 19:18:03 +00:00
from django.conf import settings
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
2016-12-13 21:22:19 +00:00
from election.models import Election, Role, Candidature
2016-12-05 19:18:03 +00:00
# Display elections
class ElectionsListView(CanViewMixin, ListView):
"""
A list with all responsabilities and their candidates
"""
model = Election
template_name = 'election/election_list.jinja'
2016-12-05 22:49:13 +00:00
2016-12-19 02:54:57 +00:00
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
2016-12-05 22:49:13 +00:00
class ElectionDetailView(CanViewMixin, DetailView):
"""
Details an election responsability by responsability
"""
model = Election
template_name = 'election/election_detail.jinja'
pk_url_kwarg = "election_id"
# Forms