Add timestamps

This commit is contained in:
Tom Hubrecht 2021-06-28 22:43:35 +02:00
parent 3601508ab2
commit 4b8ed181d8
7 changed files with 163 additions and 59 deletions

View file

@ -0,0 +1,27 @@
# Generated by Django 3.2.4 on 2021-06-28 20:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("elections", "0029_alter_election_visible"),
]
operations = [
migrations.AddField(
model_name="election",
name="time_published",
field=models.DateTimeField(
default=None, null=True, verbose_name="date de publication"
),
),
migrations.AddField(
model_name="election",
name="time_tallied",
field=models.DateTimeField(
default=None, null=True, verbose_name="date du dépouillement"
),
),
]

View file

@ -72,6 +72,13 @@ class Election(models.Model):
archived = models.BooleanField(_("archivée"), default=False) archived = models.BooleanField(_("archivée"), default=False)
time_tallied = models.DateTimeField(
_("date du dépouillement"), null=True, default=None
)
time_published = models.DateTimeField(
_("date de publication"), null=True, default=None
)
class Meta: class Meta:
permissions = [ permissions = [
("is_admin", _("Peut administrer des élections")), ("is_admin", _("Peut administrer des élections")),

View file

@ -4,15 +4,15 @@
{% block content %} {% block content %}
<div class="level"> <div class="level mb-2">
{# Titre de l'élection #} {# Titre de l'élection #}
<div class="level-left is-flex-shrink-1"> <div class="level-left is-flex-shrink-1">
<h1 class="title">{{ election.name }}</h1> <h1 class="title">{{ election.name }}</h1>
</div> </div>
<div class="level-right"> <div class="level-right is-flex">
{# Liste des votant·e·s #} {# Liste des votant·e·s #}
<div class="level-item"> <div class="level-item is-flex-grow-1 mb-0">
<a class="button is-primary is-light is-outlined" href="{% url 'election.voters' election.pk %}"> <a class="button is-primary is-light is-outlined" href="{% url 'election.voters' election.pk %}">
<span class="icon"> <span class="icon">
<i class="fas fa-clipboard-list"></i> <i class="fas fa-clipboard-list"></i>
@ -23,7 +23,7 @@
{# Liste des bulletins #} {# Liste des bulletins #}
{% if election.results_public %} {% if election.results_public %}
<div class="level-item"> <div class="level-item is-flex-grow-1 mb-0">
<a class="button is-primary is-light is-outlined" href="{% url 'election.ballots' election.pk %}"> <a class="button is-primary is-light is-outlined" href="{% url 'election.ballots' election.pk %}">
<span class="icon"> <span class="icon">
<i class="fas fa-list"></i> <i class="fas fa-list"></i>
@ -35,7 +35,7 @@
{% if election.start_date < current_time %} {% if election.start_date < current_time %}
{# Statut de l'élection #} {# Statut de l'élection #}
<div class="level-item"> <div class="level-item is-flex-grow-1 mb-0">
<span class="tag is-medium is-outlined is-light is-primary"> <span class="tag is-medium is-outlined is-light is-primary">
{% if election.end_date < current_time %} {% if election.end_date < current_time %}
{% trans "Élection terminée" %} {% trans "Élection terminée" %}
@ -48,7 +48,7 @@
{# Lien vers la page d'administration #} {# Lien vers la page d'administration #}
{% if election.created_by == user %} {% if election.created_by == user %}
<div class="level-item"> <div class="level-item is-flex-grow-1">
<a class="button has-tooltip-primary" href="{% url 'election.admin' election.pk %}" data-tooltip="{% trans "Administrer" %}"> <a class="button has-tooltip-primary" href="{% url 'election.admin' election.pk %}" data-tooltip="{% trans "Administrer" %}">
<span class="icon"> <span class="icon">
<i class="fas fa-cog"></i> <i class="fas fa-cog"></i>
@ -59,10 +59,10 @@
</div> </div>
</div> </div>
<div class="level"> <div class="level mb-2">
{# Dates d'ouverture de l'élection #} {# Dates d'ouverture de l'élection #}
<div class="level-left"> <div class="level-left is-flex">
<div class="level-item"> <div class="level-item is-flex-grow-1 mb-0">
<span class="tag is-medium is-primary"> <span class="tag is-medium is-primary">
<span class="icon-text"> <span class="icon-text">
<span>{{ election.start_date|date:"d/m/Y H:i" }}</span> <span>{{ election.start_date|date:"d/m/Y H:i" }}</span>
@ -75,7 +75,7 @@
</div> </div>
{# Créateurice de l'élection #} {# Créateurice de l'élection #}
<div class="level-item"> <div class="level-item is-flex-grow-1 mb-0">
<span class="tag is-primary is-light is-outlined">{% blocktrans with creator=election.created_by.full_name %}Créé par {{ creator }}{% endblocktrans %}</span> <span class="tag is-primary is-light is-outlined">{% blocktrans with creator=election.created_by.full_name %}Créé par {{ creator }}{% endblocktrans %}</span>
</div> </div>
</div> </div>
@ -96,6 +96,28 @@
</div> </div>
{% endif %} {% endif %}
</div> </div>
<div class="level">
<div class="level-left is-flex">
{# Date du dépouillement #}
{% if election.time_tallied %}
<div class="level-item is-flex-grow-1 mb-0">
<span class="tag is-success is-light is-outlined">
{% blocktrans with timestamp=election.time_tallied|date:"d/m/Y H:i" %}Dépouillé le {{ timestamp }}{% endblocktrans %}
</span>
</div>
{% endif %}
{# Date de la publication #}
{% if election.time_published %}
<div class="level-item is-flex-grow-1 mb-0">
<span class="tag is-info is-light is-outlined">
{% blocktrans with timestamp=election.time_published|date:"d/m/Y H:i" %}Publié le {{ timestamp }}{% endblocktrans %}
</span>
</div>
{% endif %}
</div>
</div>
<hr> <hr>
{# Précisions sur les modalités de vote #} {# Précisions sur les modalités de vote #}

View file

@ -60,23 +60,6 @@
</div> </div>
{% endif %} {% endif %}
{% if e.tallied %}
<div class="level-item">
<span class="tag is-success is-light">{% trans "Élection dépouillée" %}</span>
</div>
{% endif %}
{% if e.results_public %}
<div class="level-item">
<span class="tag is-info is-light">{% trans "Élection publiée" %}</span>
</div>
{% endif %}
{% if e.archived %}
<div class="level-item">
<span class="tag is-danger is-light">{% trans "Élection archivée" %}</span>
</div>
{% endif %}
{% if e.created_by == user %} {% if e.created_by == user %}
<div class="level-item"> <div class="level-item">
@ -91,6 +74,38 @@
</div> </div>
</div> </div>
{% if e.tallied or e.results_public or e.archived %}
<div class="panel-block">
<div class="is-flex-grow-1">
<div class="tags">
{% if e.tallied %}
<span class="tag is-success is-light is-outlined">
{% if e.time_tallied %}
{% blocktrans with timestamp=e.time_tallied|date:"d/m/Y H:i" %}Élection dépouillée le {{ timestamp }}{% endblocktrans %}
{% else %}
{% trans "Élection dépouillée" %}
{% endif %}
</span>
{% endif %}
{% if e.results_public %}
<span class="tag is-info is-light is-outlined">
{% if e.time_published %}
{% blocktrans with timestamp=e.time_published|date:"d/m/Y H:i" %}Élection publiée le {{ timestamp }}{% endblocktrans %}
{% else %}
{% trans "Élection publiée" %}
{% endif %}
</span>
{% endif %}
{% if e.archived %}
<span class="tag is-danger is-light is-outlined">{% trans "Élection archivée" %}</span>
{% endif %}
</div>
</div>
</div>
{% endif %}
{% if e.description %} {% if e.description %}
<div class="panel-block"> <div class="panel-block">
<div class="content is-flex-grow-1"> <div class="content is-flex-grow-1">

View file

@ -289,6 +289,7 @@ class ElectionTallyView(ClosedElectionMixin, BackgroundUpdateView):
q.tally() q.tally()
election.tallied = True election.tallied = True
election.time_tallied = timezone.now()
election.save() election.save()
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
@ -305,6 +306,10 @@ class ElectionChangePublicationView(ClosedElectionMixin, BackgroundUpdateView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.election = self.get_object() self.election = self.get_object()
self.election.results_public = not self.election.results_public self.election.results_public = not self.election.results_public
self.election.time_published = (
timezone.now() if self.election.results_public else None
)
self.election.save() self.election.save()
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)

View file

@ -7,8 +7,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 0.1\n" "Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-06-28 21:29+0200\n" "POT-Creation-Date: 2021-06-28 22:41+0200\n"
"PO-Revision-Date: 2021-06-28 21:30+0200\n" "PO-Revision-Date: 2021-06-28 22:43+0200\n"
"Last-Translator: Test Translator <test@translator>\n" "Last-Translator: Test Translator <test@translator>\n"
"Language-Team: \n" "Language-Team: \n"
"Language: en\n" "Language: en\n"
@ -120,51 +120,59 @@ msgstr "counted"
msgid "archivée" msgid "archivée"
msgstr "archived" msgstr "archived"
#: elections/models.py:77 #: elections/models.py:76
msgid "date du dépouillement"
msgstr "date of count"
#: elections/models.py:79
msgid "date de publication"
msgstr "date of publication"
#: elections/models.py:84
msgid "Peut administrer des élections" msgid "Peut administrer des élections"
msgstr "Can manage elections" msgstr "Can manage elections"
#: elections/models.py:87 #: elections/models.py:94
msgid "question" msgid "question"
msgstr "question" msgstr "question"
#: elections/models.py:90 #: elections/models.py:97
msgid "type de question" msgid "type de question"
msgstr "type of question" msgstr "type of question"
#: elections/models.py:97 #: elections/models.py:104
msgid "nombre maximal de votes reçus" msgid "nombre maximal de votes reçus"
msgstr "maximal number of votes received" msgstr "maximal number of votes received"
#: elections/models.py:154 #: elections/models.py:161
msgid "texte" msgid "texte"
msgstr "text" msgstr "text"
#: elections/models.py:155 #: elections/models.py:162
msgid "abréviation" msgid "abréviation"
msgstr "abbreviation" msgstr "abbreviation"
#: elections/models.py:157 #: elections/models.py:164
msgid "option gagnante" msgid "option gagnante"
msgstr "winning option" msgstr "winning option"
#: elections/models.py:165 #: elections/models.py:172
msgid "nombre de votes reçus" msgid "nombre de votes reçus"
msgstr "number of votes received" msgstr "number of votes received"
#: elections/models.py:195 #: elections/models.py:202
msgid "rang de l'option" msgid "rang de l'option"
msgstr "option's ranking" msgstr "option's ranking"
#: elections/models.py:211 #: elections/models.py:218
msgid "votes supplémentaires" msgid "votes supplémentaires"
msgstr "extra votes" msgstr "extra votes"
#: elections/models.py:227 #: elections/models.py:234
msgid "Nom et Prénom" msgid "Nom et Prénom"
msgstr "Name and surname" msgstr "Name and surname"
#: elections/models.py:250 elections/tests/test_models.py:57 #: elections/models.py:257 elections/tests/test_models.py:57
msgid "identifiants spécifiques" msgid "identifiants spécifiques"
msgstr "dedicated credentials" msgstr "dedicated credentials"
@ -241,7 +249,7 @@ msgid "Élection en cours"
msgstr "Election in progress" msgstr "Election in progress"
#: elections/templates/elections/election.html:52 #: elections/templates/elections/election.html:52
#: elections/templates/elections/election_list.html:83 #: elections/templates/elections/election_list.html:66
msgid "Administrer" msgid "Administrer"
msgstr "Manage" msgstr "Manage"
@ -254,11 +262,21 @@ msgstr "Created by %(creator)s"
msgid "Votre vote a bien été enregistré." msgid "Votre vote a bien été enregistré."
msgstr "Your vote has been recorded." msgstr "Your vote has been recorded."
#: elections/templates/elections/election.html:119 #: elections/templates/elections/election.html:106
#, python-format
msgid "Dépouillé le %(timestamp)s"
msgstr "Counted on %(timestamp)s"
#: elections/templates/elections/election.html:115
#, python-format
msgid "Publié le %(timestamp)s"
msgstr "Published on %(timestamp)s"
#: elections/templates/elections/election.html:141
msgid "Voter" msgid "Voter"
msgstr "Vote" msgstr "Vote"
#: elections/templates/elections/election.html:130 #: elections/templates/elections/election.html:152
msgid "" msgid ""
"Pour voter lors de cette élection, vous devez vous connecter à l'aide des " "Pour voter lors de cette élection, vous devez vous connecter à l'aide des "
"identifiants reçus par mail." "identifiants reçus par mail."
@ -266,7 +284,7 @@ msgstr ""
"To vote in this election, you must log in using the login credentials you " "To vote in this election, you must log in using the login credentials you "
"received by e-mail." "received by e-mail."
#: elections/templates/elections/election.html:132 #: elections/templates/elections/election.html:154
#: elections/templates/elections/election_voters.html:65 #: elections/templates/elections/election_voters.html:65
msgid "" msgid ""
"Pour voter lors de cette élection, vous devez vous connecter à l'aide du CAS " "Pour voter lors de cette élection, vous devez vous connecter à l'aide du CAS "
@ -277,16 +295,16 @@ msgstr ""
"restrictions may apply and your vote may be deleted if you are not eligible " "restrictions may apply and your vote may be deleted if you are not eligible "
"to vote." "to vote."
#: elections/templates/elections/election.html:148 #: elections/templates/elections/election.html:170
msgid "Connexion par identifiants" msgid "Connexion par identifiants"
msgstr "Login with credentials" msgstr "Login with credentials"
#: elections/templates/elections/election.html:159 #: elections/templates/elections/election.html:181
#: shared/templates/authens/login_switch.html:20 #: shared/templates/authens/login_switch.html:20
msgid "Connexion via CAS" msgid "Connexion via CAS"
msgstr "Login via CAS" msgstr "Login via CAS"
#: elections/templates/elections/election.html:194 #: elections/templates/elections/election.html:216
msgid "A voté" msgid "A voté"
msgstr "Voted" msgstr "Voted"
@ -399,15 +417,25 @@ msgstr "List of elections"
msgid "Créer une élection" msgid "Créer une élection"
msgstr "Create an election" msgstr "Create an election"
#: elections/templates/elections/election_list.html:65 #: elections/templates/elections/election_list.html:84
#, python-format
msgid "Élection dépouillée le %(timestamp)s"
msgstr "Election counted on %(timestamp)s"
#: elections/templates/elections/election_list.html:86
msgid "Élection dépouillée" msgid "Élection dépouillée"
msgstr "Election counted" msgstr "Election counted"
#: elections/templates/elections/election_list.html:71 #: elections/templates/elections/election_list.html:94
#, python-format
msgid "Élection publiée le %(timestamp)s"
msgstr "Election published on %(timestamp)s"
#: elections/templates/elections/election_list.html:96
msgid "Élection publiée" msgid "Élection publiée"
msgstr "Published election" msgstr "Published election"
#: elections/templates/elections/election_list.html:77 #: elections/templates/elections/election_list.html:102
msgid "Élection archivée" msgid "Élection archivée"
msgstr "Archived election" msgstr "Archived election"
@ -643,35 +671,35 @@ msgstr "Election successfully modified!"
msgid "Élection dépouillée avec succès !" msgid "Élection dépouillée avec succès !"
msgstr "Election successfully counted!" msgstr "Election successfully counted!"
#: elections/views.py:302 #: elections/views.py:303
msgid "Élection publiée avec succès !" msgid "Élection publiée avec succès !"
msgstr "Election successfully published!" msgstr "Election successfully published!"
#: elections/views.py:303 #: elections/views.py:304
msgid "Élection dépubliée avec succès !" msgid "Élection dépubliée avec succès !"
msgstr "Election successfully de-published!" msgstr "Election successfully de-published!"
#: elections/views.py:330 #: elections/views.py:335
msgid "Élection archivée avec succès !" msgid "Élection archivée avec succès !"
msgstr "Election successfully archived!" msgstr "Election successfully archived!"
#: elections/views.py:362 #: elections/views.py:367
msgid "Question modifiée avec succès !" msgid "Question modifiée avec succès !"
msgstr "Question successfully modified!" msgstr "Question successfully modified!"
#: elections/views.py:374 #: elections/views.py:379
msgid "Question supprimée !" msgid "Question supprimée !"
msgstr "Question deleted!" msgstr "Question deleted!"
#: elections/views.py:412 #: elections/views.py:417
msgid "Option modifiée avec succès !" msgid "Option modifiée avec succès !"
msgstr "Option successfully modified!" msgstr "Option successfully modified!"
#: elections/views.py:424 #: elections/views.py:429
msgid "Option supprimée !" msgid "Option supprimée !"
msgstr "Option deleted!" msgstr "Option deleted!"
#: elections/views.py:578 #: elections/views.py:583
msgid "Votre choix a bien été enregistré !" msgid "Votre choix a bien été enregistré !"
msgstr "Your choice has been recorded!" msgstr "Your choice has been recorded!"