Rajoute la liste des élections non archivées

This commit is contained in:
Tom Hubrecht 2021-03-20 12:25:01 +01:00
parent dcbfbfd77b
commit 79f5cdfc2b
4 changed files with 82 additions and 33 deletions

View file

@ -0,0 +1,62 @@
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<div class="level">
<div class="level-left">
<div class="level-item">
<h1 class="title">{% trans "Liste des élections créées" %}</h1>
</div>
</div>
<div class="level-right">
<div class="level-item">
<a class="button is-light is-outlined is-primary" href={% url 'election.create' %}>
<span class="icon">
<i class="fas fa-plus"></i>
</span>
<span>{% trans "Créer une élection" %}</span>
</a>
</div>
</div>
</div>
<hr>
{% for e in election_list %}
<div class="message is-primary">
<div class="message-header is-size-6 is-radiusless">
<div>
<span class="mr-2">{{ e.name }}</span>
<span class="tag is-primary is-light">{{ e.start_date|date:"d/m/Y H:i" }}</span>
<span class="icon has-text-primary-light">
<i class="fas fa-long-arrow-alt-right"></i>
</span>
<span class="tag is-primary is-light">{{ e.end_date|date:"d/m/Y H:i" }}</span>
{% if e.tallied %}
<span class="tag is-success is-light ml-3">{% trans "Élection dépouillée" %}</span>
{% endif %}
{% if e.results_public %}
<span class="tag is-info is-light ml-3">{% trans "Élection publiée" %}</span>
{% endif %}
{% if e.archived %}
<span class="tag is-danger is-light ml-3">{% trans "Élection archivée" %}</span>
{% endif %}
</div>
<a class="has-text-primary-light" href="{% url 'election.admin' e.pk %}">
<span class="icon">
<i class="fas fa-tools"></i>
</span>
<span>{% trans "" %}</span>
</a>
</div>
<p class="message-body">
{{ e.description|linebreaksbr }}
</p>
</div>
{% endfor %}
{% endblock %}

View file

@ -4,36 +4,22 @@
{% block content %} {% block content %}
<div class="level"> <h1 class="title">{% trans "Liste des élections" %}</h1>
<div class="level-left">
<div class="level-item">
<h1 class="title">{% trans "Liste des élections créées" %}</h1>
</div>
</div>
<div class="level-right">
<div class="level-item">
<a class="button is-light is-outlined is-primary" href={% url 'election.create' %}>
<span class="icon">
<i class="fas fa-plus"></i>
</span>
<span>{% trans "Créer une élection" %}</span>
</a>
</div>
</div>
</div>
<hr> <hr>
{% for e in election_list %} {% for e in election_list %}
<div class="message is-primary"> <div class="message is-primary">
<div class="message-header is-size-6 is-radiusless"> <div class="message-header is-size-6 is-radiusless">
<div> <div>
<span class="mr-2">{{ e.name }}</span> <a href="{% url 'election.view' e.pk %}">{{ e.name }}</a>
<span class="tag is-primary is-light">{{ e.start_date|date:"d/m/Y H:i" }}</span> <span class="tag is-primary is-light ml-3">{{ e.start_date|date:"d/m/Y H:i" }}</span>
<span class="icon has-text-primary-light"> <span class="icon has-text-primary-light">
<i class="fas fa-long-arrow-alt-right"></i> <i class="fas fa-long-arrow-alt-right"></i>
</span> </span>
<span class="tag is-primary is-light">{{ e.end_date|date:"d/m/Y H:i" }}</span> <span class="tag is-primary is-light">{{ e.end_date|date:"d/m/Y H:i" }}</span>
</div>
<div>
{% if e.tallied %} {% if e.tallied %}
<span class="tag is-success is-light ml-3">{% trans "Élection dépouillée" %}</span> <span class="tag is-success is-light ml-3">{% trans "Élection dépouillée" %}</span>
{% endif %} {% endif %}
@ -41,17 +27,7 @@
{% if e.results_public %} {% if e.results_public %}
<span class="tag is-info is-light ml-3">{% trans "Élection publiée" %}</span> <span class="tag is-info is-light ml-3">{% trans "Élection publiée" %}</span>
{% endif %} {% endif %}
{% if e.archived %}
<span class="tag is-danger is-light ml-3">{% trans "Élection archivée" %}</span>
{% endif %}
</div> </div>
<a class="has-text-primary-light" href="{% url 'election.admin' e.pk %}">
<span class="icon">
<i class="fas fa-tools"></i>
</span>
<span>{% trans "" %}</span>
</a>
</div> </div>
<p class="message-body"> <p class="message-body">
{{ e.description|linebreaksbr }} {{ e.description|linebreaksbr }}

View file

@ -5,7 +5,7 @@ from . import views
urlpatterns = [ urlpatterns = [
# Admin views # Admin views
path("create/", views.ElectionCreateView.as_view(), name="election.create"), path("create/", views.ElectionCreateView.as_view(), name="election.create"),
path("created/", views.ElectionListView.as_view(), name="election.created"), path("created/", views.ElectionCreatedView.as_view(), name="election.created"),
path("admin/<int:pk>", views.ElectionAdminView.as_view(), name="election.admin"), path("admin/<int:pk>", views.ElectionAdminView.as_view(), name="election.admin"),
path( path(
"mail-voters/<int:pk>", "mail-voters/<int:pk>",
@ -60,6 +60,7 @@ urlpatterns = [
name="election.del-option", name="election.del-option",
), ),
# Common views # Common views
path("list", views.ElectionListView.as_view(), name="election.list"),
path("view/<int:pk>", views.ElectionView.as_view(), name="election.view"), path("view/<int:pk>", views.ElectionView.as_view(), name="election.view"),
path( path(
"view/<int:pk>/voters", "view/<int:pk>/voters",

View file

@ -157,9 +157,9 @@ class ElectionMailVotersView(CreatorOnlyEditMixin, SuccessMessageMixin, FormView
return super().form_valid(form) return super().form_valid(form)
class ElectionListView(CreatorOnlyMixin, ListView): class ElectionCreatedView(CreatorOnlyMixin, ListView):
model = Election model = Election
template_name = "elections/election_list.html" template_name = "elections/election_created.html"
class ElectionUpdateView(CreatorOnlyEditMixin, SuccessMessageMixin, UpdateView): class ElectionUpdateView(CreatorOnlyEditMixin, SuccessMessageMixin, UpdateView):
@ -195,7 +195,9 @@ class ElectionTallyView(CreatorOnlyMixin, SingleObjectMixin, BackgroundUpdateVie
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
class ElectionChangePublicationView(CreatorOnlyEditMixin, BackgroundUpdateView): class ElectionChangePublicationView(
CreatorOnlyMixin, SingleObjectMixin, BackgroundUpdateView
):
model = Election model = Election
pattern_name = "election.admin" pattern_name = "election.admin"
@ -332,6 +334,14 @@ class DelOptionView(CreatorOnlyEditMixin, BackgroundUpdateView):
# ############################################################################# # #############################################################################
class ElectionListView(ListView):
model = Election
template_name = "elections/election_list.html"
def get_queryset(self):
return super().get_queryset().filter(archived=False)
class ElectionView(DetailView): class ElectionView(DetailView):
model = Election model = Election
template_name = "elections/election.html" template_name = "elections/election.html"