mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
Add a way for admin to delete elections and add archive system
This commit is contained in:
19
election/migrations/0002_election_archived.py
Normal file
19
election/migrations/0002_election_archived.py
Normal 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),
|
||||
),
|
||||
]
|
@ -31,6 +31,7 @@ class Election(models.Model):
|
||||
verbose_name=_("candidature groups"), blank=True)
|
||||
voters = models.ManyToManyField(User, verbose_name=(
|
||||
'voters'), related_name='voted_elections')
|
||||
archived = models.BooleanField(_("archived"), default=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
@ -373,6 +373,9 @@ th {
|
||||
{% endif %}
|
||||
<a href="{{ url('election:update', election_id=object.id) }}">{% trans %}Edit{% endtrans %}</a>
|
||||
{%- endif %}
|
||||
{%- if user.is_root %}
|
||||
<a href="{{ url('election:delete', election_id=object.id) }}">{% trans %}Delete{% endtrans %}</a>
|
||||
{%- endif %}
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -4,9 +4,13 @@ from election.views import *
|
||||
|
||||
urlpatterns = [
|
||||
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'^(?P<election_id>[0-9]+)/edit$',
|
||||
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$',
|
||||
ElectionListCreateView.as_view(), name='create_list'),
|
||||
url(r'^(?P<election_id>[0-9]+)/role/create$',
|
||||
|
@ -129,7 +129,7 @@ class ElectionListForm(forms.ModelForm):
|
||||
class ElectionForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Election
|
||||
fields = ['title', 'description',
|
||||
fields = ['title', 'description', 'archived',
|
||||
'start_candidature', 'end_candidature',
|
||||
'start_date', 'end_date',
|
||||
'edit_groups', 'view_groups',
|
||||
@ -161,13 +161,31 @@ class ElectionForm(forms.ModelForm):
|
||||
|
||||
class ElectionsListView(CanViewMixin, ListView):
|
||||
"""
|
||||
A list with all responsabilities and their candidates
|
||||
A list of all non archived elections visible
|
||||
"""
|
||||
model = Election
|
||||
ordering = ["-id"]
|
||||
paginate_by = 10
|
||||
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):
|
||||
"""
|
||||
@ -515,6 +533,21 @@ class RoleUpdateView(CanEditMixin, UpdateView):
|
||||
# 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):
|
||||
model = Candidature
|
||||
template_name = 'core/delete_confirm.jinja'
|
||||
|
Reference in New Issue
Block a user