Add a way for admin to delete elections and add archive system

This commit is contained in:
Antoine Bartuccio 2017-06-07 17:33:46 +02:00
parent 0076c9cdb4
commit c4389bb9cd
7 changed files with 119 additions and 53 deletions

View File

@ -103,6 +103,7 @@
<h4>{% trans %}Elections{% endtrans %}</h4> <h4>{% trans %}Elections{% endtrans %}</h4>
<ul> <ul>
<li><a href="{{ url('election:list') }}">{% trans %}See available elections{% endtrans %}</a></li> <li><a href="{{ url('election:list') }}">{% trans %}See available elections{% endtrans %}</a></li>
<li><a href="{{ url('election:list_archived') }}">{% trans %}See archived elections{% endtrans %}</a></li>
{%- if user.is_subscribed -%} {%- if user.is_subscribed -%}
<li><a href="{{ url('election:create') }}">{% trans %}Create a new election{% endtrans %}</a></li> <li><a href="{{ url('election:create') }}">{% trans %}Create a new election{% endtrans %}</a></li>
{%- endif -%} {%- endif -%}

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('election', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='election',
name='archived',
field=models.BooleanField(verbose_name='archived', default=False),
),
]

View File

@ -31,6 +31,7 @@ class Election(models.Model):
verbose_name=_("candidature groups"), blank=True) verbose_name=_("candidature groups"), blank=True)
voters = models.ManyToManyField(User, verbose_name=( voters = models.ManyToManyField(User, verbose_name=(
'voters'), related_name='voted_elections') 'voters'), related_name='voted_elections')
archived = models.BooleanField(_("archived"), default=False)
def __str__(self): def __str__(self):
return self.title return self.title

View File

@ -373,6 +373,9 @@ th {
{% endif %} {% endif %}
<a href="{{ url('election:update', election_id=object.id) }}">{% trans %}Edit{% endtrans %}</a> <a href="{{ url('election:update', election_id=object.id) }}">{% trans %}Edit{% endtrans %}</a>
{%- endif %} {%- endif %}
{%- if user.is_root %}
<a href="{{ url('election:delete', election_id=object.id) }}">{% trans %}Delete{% endtrans %}</a>
{%- endif %}
</section> </section>
{% endblock %} {% endblock %}

View File

@ -4,9 +4,13 @@ from election.views import *
urlpatterns = [ urlpatterns = [
url(r'^$', ElectionsListView.as_view(), name='list'), url(r'^$', ElectionsListView.as_view(), name='list'),
url(r'^archived$',
ElectionListArchivedView.as_view(), name='list_archived'),
url(r'^add$', ElectionCreateView.as_view(), name='create'), url(r'^add$', ElectionCreateView.as_view(), name='create'),
url(r'^(?P<election_id>[0-9]+)/edit$', url(r'^(?P<election_id>[0-9]+)/edit$',
ElectionUpdateView.as_view(), name='update'), ElectionUpdateView.as_view(), name='update'),
url(r'^(?P<election_id>[0-9]+)/delete$',
ElectionDeleteView.as_view(), name='delete'),
url(r'^(?P<election_id>[0-9]+)/list/add$', url(r'^(?P<election_id>[0-9]+)/list/add$',
ElectionListCreateView.as_view(), name='create_list'), ElectionListCreateView.as_view(), name='create_list'),
url(r'^(?P<election_id>[0-9]+)/role/create$', url(r'^(?P<election_id>[0-9]+)/role/create$',

View File

@ -129,7 +129,7 @@ class ElectionListForm(forms.ModelForm):
class ElectionForm(forms.ModelForm): class ElectionForm(forms.ModelForm):
class Meta: class Meta:
model = Election model = Election
fields = ['title', 'description', fields = ['title', 'description', 'archived',
'start_candidature', 'end_candidature', 'start_candidature', 'end_candidature',
'start_date', 'end_date', 'start_date', 'end_date',
'edit_groups', 'view_groups', 'edit_groups', 'view_groups',
@ -161,13 +161,31 @@ class ElectionForm(forms.ModelForm):
class ElectionsListView(CanViewMixin, ListView): class ElectionsListView(CanViewMixin, ListView):
""" """
A list with all responsabilities and their candidates A list of all non archived elections visible
""" """
model = Election model = Election
ordering = ["-id"] ordering = ["-id"]
paginate_by = 10 paginate_by = 10
template_name = 'election/election_list.jinja' template_name = 'election/election_list.jinja'
def get_queryset(self):
return super(ElectionsListView,
self).get_queryset().filter(archived=False).all()
class ElectionListArchivedView(CanViewMixin, ListView):
"""
A list of all archived elections visible
"""
model = Election
ordering = ["-id"]
paginate_by = 10
template_name = 'election/election_list.jinja'
def get_queryset(self):
return super(ElectionListArchivedView,
self).get_queryset().filter(archived=True).all()
class ElectionDetailView(CanViewMixin, DetailView): class ElectionDetailView(CanViewMixin, DetailView):
""" """
@ -515,6 +533,21 @@ class RoleUpdateView(CanEditMixin, UpdateView):
# Delete Views # Delete Views
class ElectionDeleteView(DeleteView):
model = Election
template_name = 'core/delete_confirm.jinja'
pk_url_kwarg = 'election_id'
def dispatch(self, request, *args, **kwargs):
if request.user.is_root:
return super(ElectionDeleteView,
self).dispatch(request, *args, **kwargs)
raise PermissionDenied
def get_success_url(self, **kwargs):
return reverse_lazy('election:list')
class CandidatureDeleteView(CanEditMixin, DeleteView): class CandidatureDeleteView(CanEditMixin, DeleteView):
model = Candidature model = Candidature
template_name = 'core/delete_confirm.jinja' template_name = 'core/delete_confirm.jinja'

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-06 23:25+0200\n" "POT-Creation-Date: 2017-06-07 17:32+0200\n"
"PO-Revision-Date: 2016-07-18\n" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Skia <skia@libskia.so>\n" "Last-Translator: Skia <skia@libskia.so>\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@ -88,12 +88,12 @@ msgid "%(club_account)s on %(bank_account)s"
msgstr "%(club_account)s sur %(bank_account)s" msgstr "%(club_account)s sur %(bank_account)s"
#: accounting/models.py:192 club/models.py:184 counter/models.py:433 #: accounting/models.py:192 club/models.py:184 counter/models.py:433
#: election/models.py:18 launderette/models.py:144 #: election/models.py:17 launderette/models.py:144
msgid "start date" msgid "start date"
msgstr "date de début" msgstr "date de début"
#: accounting/models.py:193 club/models.py:185 counter/models.py:434 #: accounting/models.py:193 club/models.py:185 counter/models.py:434
#: election/models.py:19 #: election/models.py:18
msgid "end date" msgid "end date"
msgstr "date de fin" msgstr "date de fin"
@ -335,6 +335,7 @@ msgstr "Compte en banque : "
#: counter/templates/counter/last_ops.jinja:59 #: counter/templates/counter/last_ops.jinja:59
#: election/templates/election/election_detail.jinja:280 #: election/templates/election/election_detail.jinja:280
#: election/templates/election/election_detail.jinja:329 #: election/templates/election/election_detail.jinja:329
#: election/templates/election/election_detail.jinja:377
#: forum/templates/forum/macros.jinja:21 forum/templates/forum/macros.jinja:123 #: forum/templates/forum/macros.jinja:21 forum/templates/forum/macros.jinja:123
#: launderette/templates/launderette/launderette_admin.jinja:16 #: launderette/templates/launderette/launderette_admin.jinja:16
#: launderette/views.py:178 sas/templates/sas/album.jinja:26 #: launderette/views.py:178 sas/templates/sas/album.jinja:26
@ -830,19 +831,19 @@ msgid "A club with that unix_name already exists"
msgstr "Un club avec ce nom UNIX existe déjà." msgstr "Un club avec ce nom UNIX existe déjà."
#: club/models.py:182 counter/models.py:431 counter/models.py:448 #: club/models.py:182 counter/models.py:431 counter/models.py:448
#: eboutic/models.py:38 eboutic/models.py:71 election/models.py:130 #: eboutic/models.py:38 eboutic/models.py:71 election/models.py:147
#: launderette/models.py:111 launderette/models.py:148 sas/models.py:156 #: launderette/models.py:111 launderette/models.py:148 sas/models.py:156
msgid "user" msgid "user"
msgstr "nom d'utilisateur" msgstr "nom d'utilisateur"
#: club/models.py:186 core/models.py:169 election/models.py:129 #: club/models.py:186 core/models.py:169 election/models.py:145
#: election/models.py:145 #: election/models.py:165
msgid "role" msgid "role"
msgstr "rôle" msgstr "rôle"
#: club/models.py:188 core/models.py:61 counter/models.py:101 #: club/models.py:188 core/models.py:61 counter/models.py:101
#: counter/models.py:126 election/models.py:15 election/models.py:82 #: counter/models.py:126 election/models.py:13 election/models.py:93
#: election/models.py:131 forum/models.py:51 forum/models.py:184 #: election/models.py:148 forum/models.py:51 forum/models.py:184
msgid "description" msgid "description"
msgstr "description" msgstr "description"
@ -1069,6 +1070,7 @@ msgstr "Date de début"
#: club/views.py:196 com/views.py:123 counter/views.py:1020 #: club/views.py:196 com/views.py:123 counter/views.py:1020
#: election/views.py:131 subscription/views.py:50 #: election/views.py:131 subscription/views.py:50
#: election/views.py:149
msgid "End date" msgid "End date"
msgstr "Date de fin" msgstr "Date de fin"
@ -1109,8 +1111,8 @@ msgstr "Hebdomadaire"
msgid "Call" msgid "Call"
msgstr "Appel" msgstr "Appel"
#: com/models.py:60 com/models.py:102 com/models.py:149 election/models.py:14 #: com/models.py:60 com/models.py:102 com/models.py:149 election/models.py:12
#: election/models.py:81 election/models.py:118 forum/models.py:187 #: election/models.py:92 election/models.py:132 forum/models.py:187
#: forum/models.py:234 #: forum/models.py:234
msgid "title" msgid "title"
msgstr "titre" msgstr "titre"
@ -1416,6 +1418,7 @@ msgid "Alert message"
msgstr "Message d'alerte" msgstr "Message d'alerte"
#: com/views.py:122 election/views.py:130 subscription/views.py:47 #: com/views.py:122 election/views.py:130 subscription/views.py:47
#: com/views.py:122 election/views.py:146
msgid "Start date" msgid "Start date"
msgstr "Date de début" msgstr "Date de début"
@ -2145,6 +2148,18 @@ msgstr "Créneau"
msgid "Tokens" msgid "Tokens"
msgstr "Jetons" msgstr "Jetons"
#: core/templates/core/macros.jinja:78 core/templates/core/macros.jinja:80
msgid "Previous"
msgstr "Précédent"
#: core/templates/core/macros.jinja:84
msgid "current"
msgstr "actuel"
#: core/templates/core/macros.jinja:90 core/templates/core/macros.jinja:92
msgid "Next"
msgstr "Suivant"
#: core/templates/core/new_user_email.jinja:2 #: core/templates/core/new_user_email.jinja:2
msgid "" msgid ""
"You're receiving this email because you subscribed to the UTBM student " "You're receiving this email because you subscribed to the UTBM student "
@ -2698,6 +2713,10 @@ msgstr "Élections"
msgid "See available elections" msgid "See available elections"
msgstr "Voir les élections disponibles" msgstr "Voir les élections disponibles"
#: core/templates/core/user_tools.jinja:105
msgid "See archived elections"
msgstr "Voir les élections archivées"
#: core/templates/core/user_tools.jinja:107 #: core/templates/core/user_tools.jinja:107
msgid "Create a new election" msgid "Create a new election"
msgstr "Créer une nouvelle élection" msgstr "Créer une nouvelle élection"
@ -2834,7 +2853,7 @@ msgstr "produit parent"
msgid "buying groups" msgid "buying groups"
msgstr "groupe d'achat" msgstr "groupe d'achat"
#: counter/models.py:140 #: counter/models.py:140 election/models.py:34
msgid "archived" msgid "archived"
msgstr "archivé" msgstr "archivé"
@ -3035,21 +3054,7 @@ msgstr "Coffre vidé"
msgid "yes" msgid "yes"
msgstr "oui" msgstr "oui"
#: counter/templates/counter/cash_summary_list.jinja:61
#: counter/templates/counter/cash_summary_list.jinja:63 #: counter/templates/counter/cash_summary_list.jinja:63
msgid "Previous"
msgstr "Précédent"
#: counter/templates/counter/cash_summary_list.jinja:67
msgid "current"
msgstr "actuel"
#: counter/templates/counter/cash_summary_list.jinja:73
#: counter/templates/counter/cash_summary_list.jinja:75
msgid "Next"
msgstr "Suivant"
#: counter/templates/counter/cash_summary_list.jinja:79
msgid "There is no cash register summary in this website." msgid "There is no cash register summary in this website."
msgstr "Il n'y a pas de relevé de caisse dans ce site web." msgstr "Il n'y a pas de relevé de caisse dans ce site web."
@ -3434,43 +3439,43 @@ msgstr "Retourner à l'eboutic"
msgid "You do not have enough money to buy the basket" msgid "You do not have enough money to buy the basket"
msgstr "Vous n'avez pas assez d'argent pour acheter le panier" msgstr "Vous n'avez pas assez d'argent pour acheter le panier"
#: election/models.py:16 #: election/models.py:15
msgid "start candidature" msgid "start candidature"
msgstr "début des candidatures" msgstr "début des candidatures"
#: election/models.py:17 #: election/models.py:16
msgid "end candidature" msgid "end candidature"
msgstr "fin des candidatures" msgstr "fin des candidatures"
#: election/models.py:21 #: election/models.py:22
msgid "edit groups" msgid "edit groups"
msgstr "groupe d'édition" msgstr "groupe d'édition"
#: election/models.py:22 #: election/models.py:25
msgid "view groups" msgid "view groups"
msgstr "groupe de vue" msgstr "groupe de vue"
#: election/models.py:23 #: election/models.py:28
msgid "vote groups" msgid "vote groups"
msgstr "groupe de vote" msgstr "groupe de vote"
#: election/models.py:24 #: election/models.py:31
msgid "candidature groups" msgid "candidature groups"
msgstr "groupe de candidature" msgstr "groupe de candidature"
#: election/models.py:80 election/models.py:119 #: election/models.py:91 election/models.py:134
msgid "election" msgid "election"
msgstr "élection" msgstr "élection"
#: election/models.py:83 #: election/models.py:94
msgid "max choice" msgid "max choice"
msgstr "nombre de choix maxi" msgstr "nombre de choix maxi"
#: election/models.py:132 #: election/models.py:151
msgid "election list" msgid "election list"
msgstr "liste électorale" msgstr "liste électorale"
#: election/models.py:146 #: election/models.py:167
msgid "candidature" msgid "candidature"
msgstr "candidature" msgstr "candidature"
@ -3498,10 +3503,10 @@ msgstr "Les votes ouvriront "
#: election/templates/election/election_detail.jinja:243 #: election/templates/election/election_detail.jinja:243
#: election/templates/election/election_detail.jinja:247 #: election/templates/election/election_detail.jinja:247
#: election/templates/election/election_list.jinja:31 #: election/templates/election/election_list.jinja:32
#: election/templates/election/election_list.jinja:34 #: election/templates/election/election_list.jinja:35
#: election/templates/election/election_list.jinja:39 #: election/templates/election/election_list.jinja:40
#: election/templates/election/election_list.jinja:42 #: election/templates/election/election_list.jinja:43
#: forum/templates/forum/macros.jinja:137 #: forum/templates/forum/macros.jinja:137
msgid " at " msgid " at "
msgstr " à " msgstr " à "
@ -3518,7 +3523,7 @@ msgstr "Vous avez déjà soumis votre vote."
msgid "You have voted in this election." msgid "You have voted in this election."
msgstr "Vous avez déjà voté pour cette élection." msgstr "Vous avez déjà voté pour cette élection."
#: election/templates/election/election_detail.jinja:266 election/views.py:82 #: election/templates/election/election_detail.jinja:266 election/views.py:90
msgid "Blank vote" msgid "Blank vote"
msgstr "Vote blanc" msgstr "Vote blanc"
@ -3556,44 +3561,44 @@ msgstr "Ajouter une nouvelle liste"
msgid "Add a new role" msgid "Add a new role"
msgstr "Ajouter un nouveau rôle" msgstr "Ajouter un nouveau rôle"
#: election/templates/election/election_list.jinja:4 #: election/templates/election/election_list.jinja:5
msgid "Election list" msgid "Election list"
msgstr "Liste des élections" msgstr "Liste des élections"
#: election/templates/election/election_list.jinja:21 #: election/templates/election/election_list.jinja:22
msgid "Current elections" msgid "Current elections"
msgstr "Élections actuelles" msgstr "Élections actuelles"
#: election/templates/election/election_list.jinja:29 #: election/templates/election/election_list.jinja:30
msgid "Applications open from" msgid "Applications open from"
msgstr "Candidatures ouvertes à partir du" msgstr "Candidatures ouvertes à partir du"
#: election/templates/election/election_list.jinja:32 #: election/templates/election/election_list.jinja:33
#: election/templates/election/election_list.jinja:40 #: election/templates/election/election_list.jinja:41
msgid "to" msgid "to"
msgstr "au" msgstr "au"
#: election/templates/election/election_list.jinja:37 #: election/templates/election/election_list.jinja:38
msgid "Polls open from" msgid "Polls open from"
msgstr "Votes ouverts du" msgstr "Votes ouverts du"
#: election/views.py:44 #: election/views.py:46
msgid "You have selected too much candidates." msgid "You have selected too much candidates."
msgstr "Vous avez sélectionné trop de candidats." msgstr "Vous avez sélectionné trop de candidats."
#: election/views.py:59 #: election/views.py:62
msgid "User to candidate" msgid "User to candidate"
msgstr "Utilisateur se présentant" msgstr "Utilisateur se présentant"
#: election/views.py:102 #: election/views.py:112
msgid "This role already exists for this election" msgid "This role already exists for this election"
msgstr "Ce rôle existe déjà pour cette élection" msgstr "Ce rôle existe déjà pour cette élection"
#: election/views.py:132 #: election/views.py:152
msgid "Start candidature" msgid "Start candidature"
msgstr "Début des candidatures" msgstr "Début des candidatures"
#: election/views.py:133 #: election/views.py:155
msgid "End candidature" msgid "End candidature"
msgstr "Fin des candidatures" msgstr "Fin des candidatures"