From f2b4e9bcfea4eef2269b76ac5fa968aac1692f8c Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sat, 21 Aug 2021 22:58:01 +0200 Subject: [PATCH] Use AJAX to edit options and questions --- .../templates/elections/admin/option.html | 40 ++++ .../templates/elections/admin/question.html | 71 +++++++ .../templates/elections/election_admin.html | 180 +++++++----------- elections/urls.py | 12 +- elections/views.py | 85 ++------- shared/json/views.py | 93 +++++++++ shared/static/js/main.js | 167 ++++++++++++++++ shared/templates/base.html | 162 +--------------- shared/templates/forms/modal-form.html | 6 +- shared/views.py | 7 + 10 files changed, 474 insertions(+), 349 deletions(-) create mode 100644 elections/templates/elections/admin/option.html create mode 100644 elections/templates/elections/admin/question.html create mode 100644 shared/json/views.py create mode 100644 shared/static/js/main.js diff --git a/elections/templates/elections/admin/option.html b/elections/templates/elections/admin/option.html new file mode 100644 index 0000000..fc5a6e3 --- /dev/null +++ b/elections/templates/elections/admin/option.html @@ -0,0 +1,40 @@ +{% load i18n markdown %} + +
+ {% if o.question.election.start_date > current_time %} + + + + + + + + + + + + + + + {% elif o.question.election.tallied %} + + + {% if q.vote_type == "select" %} + + + + {{ o.nb_votes }} + + {% elif q.vote_type == "rank" %} + + + + + {% if o.abbreviation %}{{ o.abbreviation }}{% else %}{{ forloop.counter }}{% endif %} + {% endif %} + + {% endif %} + + + {{ o }} +
diff --git a/elections/templates/elections/admin/question.html b/elections/templates/elections/admin/question.html new file mode 100644 index 0000000..a3b9f0d --- /dev/null +++ b/elections/templates/elections/admin/question.html @@ -0,0 +1,71 @@ +{% load i18n markdown %} + +
+
+
+
+
+ + + + + {{ q }} + +
+ + {% if q.election.start_date > current_time %} + + {% endif %} +
+ +
+ {{ q.get_type_display }} +
+
+
+ + {# Liste des options possibles #} +
+ {% for o in q.options.all %} + {% include 'elections/admin/option.html' %} + {% endfor %} +
+ + {# Permet d'afficher une ligne #} +
+ + {# Affiche plus d'informations sur le résultat #} + {% if q.election.tallied %} + {{ q.get_results_data }} + {% endif %} + + {# Rajout d'une option #} + {% if q.election.start_date > current_time %} +
+ +
+ {% endif %} +
diff --git a/elections/templates/elections/election_admin.html b/elections/templates/elections/election_admin.html index fecb9fc..59a0065 100644 --- a/elections/templates/elections/election_admin.html +++ b/elections/templates/elections/election_admin.html @@ -2,21 +2,69 @@ {% load i18n markdown %} -{% block extra_head %} +{% block custom_js %} + {% block extra_head %}{% endblock extra_head %} diff --git a/shared/templates/forms/modal-form.html b/shared/templates/forms/modal-form.html index f36a564..50dc23d 100644 --- a/shared/templates/forms/modal-form.html +++ b/shared/templates/forms/modal-form.html @@ -1,14 +1,14 @@ {% load i18n %}