views.py 1.15 KB
Newer Older
Sli's avatar
Sli committed
1
2
3
4
5
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 _
Sli's avatar
Sli committed
6
from django.utils import timezone
Sli's avatar
Sli committed
7
8
9
from django.conf import settings

from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
Sli's avatar
Sli committed
10
from election.models import Election, Role, Candidature
Sli's avatar
Sli committed
11
12
13
14
15
16
17
18
19
20

# Display elections


class ElectionsListView(CanViewMixin, ListView):
    """
    A list with all responsabilities and their candidates
    """
    model = Election
    template_name = 'election/election_list.jinja'
Sli's avatar
Sli committed
21

Sli's avatar
Sli committed
22
23
24
25
26
27
    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

Sli's avatar
Sli committed
28
29
30
31
32
33
34
35
36
37

class ElectionDetailView(CanViewMixin, DetailView):
    """
    Details an election responsability by responsability
    """
    model = Election
    template_name = 'election/election_detail.jinja'
    pk_url_kwarg = "election_id"

# Forms