mirror of https://gitlab.crans.org/bde/nk20
[WEI] Implement WEI Survey front
This commit is contained in:
parent
ad59b5c81e
commit
e4998cb6e3
|
@ -44,6 +44,13 @@ class WEIBusInformation:
|
||||||
def __init__(self, bus: Bus):
|
def __init__(self, bus: Bus):
|
||||||
self.__dict__.update(bus.information)
|
self.__dict__.update(bus.information)
|
||||||
self.bus = bus
|
self.bus = bus
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
d = self.__dict__.copy()
|
||||||
|
d.pop("bus")
|
||||||
|
self.bus.information = d
|
||||||
|
self.bus.save()
|
||||||
|
|
||||||
|
|
||||||
class WEISurveyAlgorithm:
|
class WEISurveyAlgorithm:
|
||||||
|
|
|
@ -1,27 +1,56 @@
|
||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from django import forms
|
from random import choice
|
||||||
|
|
||||||
from .base import WEISurvey, WEISurveyInformation, WEISurveyAlgorithm
|
from django import forms
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from .base import WEISurvey, WEISurveyInformation, WEISurveyAlgorithm, WEIBusInformation
|
||||||
from ...models import Bus
|
from ...models import Bus
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Use new words
|
||||||
|
WORDS = ['Rap', 'Retro', 'DJ', 'Rock', 'Jazz', 'Chansons Populaires', 'Chansons Paillardes', 'Pop', 'Fanfare',
|
||||||
|
'Biere', 'Pastis', 'Vodka', 'Cocktails', 'Eau', 'Sirop', 'Jus de fruit', 'Binge Drinking', 'Rhum',
|
||||||
|
'Eau de vie', 'Apéro', 'Morning beer', 'Huit-six', 'Jeux de societé', 'Jeux de cartes', 'Danse', 'Karaoké',
|
||||||
|
'Bière Pong', 'Poker', 'Loup Garou', 'Films', "Jeux d'alcool", 'Sport', 'Rangées de cul', 'Chips', 'BBQ',
|
||||||
|
'Kebab', 'Saucisse', 'Vegan', 'Vege', 'LGBTIQ+', 'Dab', 'Solitaire', 'Séducteur', 'Sociale', 'Chanteur',
|
||||||
|
'Se lacher', 'Chill', 'Débile', 'Beauf', 'Bon enfant']
|
||||||
|
|
||||||
|
|
||||||
class WEISurveyForm2020(forms.Form):
|
class WEISurveyForm2020(forms.Form):
|
||||||
"""
|
"""
|
||||||
Survey form for the year 2020.
|
Survey form for the year 2020.
|
||||||
For now, that's only a Bus selector.
|
Members choose 20 words, from which we calculate the best associated bus.
|
||||||
TODO: Do a better survey (later)
|
|
||||||
"""
|
"""
|
||||||
bus = forms.ModelChoiceField(
|
|
||||||
Bus.objects,
|
word = forms.ChoiceField(
|
||||||
|
label=_("Choose a word:"),
|
||||||
|
widget=forms.RadioSelect(),
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_registration(self, registration):
|
def set_registration(self, registration):
|
||||||
"""
|
"""
|
||||||
Filter the bus selector with the buses of the current WEI.
|
Filter the bus selector with the buses of the current WEI.
|
||||||
"""
|
"""
|
||||||
self.fields["bus"].queryset = Bus.objects.filter(wei=registration.wei)
|
words = [choice(WORDS) for _ in range(10)]
|
||||||
|
words = [(w, w) for w in words]
|
||||||
|
if self.data:
|
||||||
|
self.fields["word"].choices = WORDS
|
||||||
|
if self.is_valid():
|
||||||
|
return
|
||||||
|
self.fields["word"].choices = words
|
||||||
|
|
||||||
|
|
||||||
|
class WEIBusInformation2020(WEIBusInformation):
|
||||||
|
"""
|
||||||
|
For each word, the bus has a score
|
||||||
|
"""
|
||||||
|
def __init__(self, bus):
|
||||||
|
for word in WORDS:
|
||||||
|
setattr(self, word, 0.0)
|
||||||
|
super().__init__(bus)
|
||||||
|
|
||||||
|
|
||||||
class WEISurveyInformation2020(WEISurveyInformation):
|
class WEISurveyInformation2020(WEISurveyInformation):
|
||||||
|
@ -29,14 +58,19 @@ class WEISurveyInformation2020(WEISurveyInformation):
|
||||||
We store the id of the selected bus. We store only the name, but is not used in the selection:
|
We store the id of the selected bus. We store only the name, but is not used in the selection:
|
||||||
that's only for humans that try to read data.
|
that's only for humans that try to read data.
|
||||||
"""
|
"""
|
||||||
chosen_bus_pk = None
|
step = 0
|
||||||
chosen_bus_name = None
|
|
||||||
|
def __init__(self, registration):
|
||||||
|
for i in range(1, 21):
|
||||||
|
setattr(self, "word" + str(i), None)
|
||||||
|
super().__init__(registration)
|
||||||
|
|
||||||
|
|
||||||
class WEISurvey2020(WEISurvey):
|
class WEISurvey2020(WEISurvey):
|
||||||
"""
|
"""
|
||||||
Survey for the year 2020.
|
Survey for the year 2020.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_year(cls):
|
def get_year(cls):
|
||||||
return 2020
|
return 2020
|
||||||
|
@ -55,9 +89,9 @@ class WEISurvey2020(WEISurvey):
|
||||||
form.set_registration(self.registration)
|
form.set_registration(self.registration)
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
bus = form.cleaned_data["bus"]
|
word = form.cleaned_data["word"]
|
||||||
self.information.chosen_bus_pk = bus.pk
|
self.information.step += 1
|
||||||
self.information.chosen_bus_name = bus.name
|
setattr(self.information, "word" + str(self.information.step), word)
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -68,7 +102,7 @@ class WEISurvey2020(WEISurvey):
|
||||||
"""
|
"""
|
||||||
The survey is complete once the bus is chosen.
|
The survey is complete once the bus is chosen.
|
||||||
"""
|
"""
|
||||||
return self.information.chosen_bus_pk is not None
|
return self.information.step == 20
|
||||||
|
|
||||||
|
|
||||||
class WEISurveyAlgorithm2020(WEISurveyAlgorithm):
|
class WEISurveyAlgorithm2020(WEISurveyAlgorithm):
|
||||||
|
@ -82,8 +116,12 @@ class WEISurveyAlgorithm2020(WEISurveyAlgorithm):
|
||||||
def get_survey_class(cls):
|
def get_survey_class(cls):
|
||||||
return WEISurvey2020
|
return WEISurvey2020
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_bus_information_class(cls):
|
||||||
|
return WEIBusInformation2020
|
||||||
|
|
||||||
def run_algorithm(self):
|
def run_algorithm(self):
|
||||||
for registration in self.get_registrations():
|
for registration in self.get_registrations():
|
||||||
survey = self.get_survey_class()(registration)
|
survey = self.get_survey_class()(registration)
|
||||||
survey.select_bus(Bus.objects.get(pk=survey.information.chosen_bus_pk))
|
survey.select_bus(choice(Bus.objects.all()))
|
||||||
survey.save()
|
survey.save()
|
||||||
|
|
|
@ -918,6 +918,7 @@ class WEISurveyView(LoginRequiredMixin, BaseFormView, DetailView):
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
|
self.object = obj
|
||||||
|
|
||||||
wei = obj.wei
|
wei = obj.wei
|
||||||
today = date.today()
|
today = date.today()
|
||||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2020-08-07 14:17+0200\n"
|
"POT-Creation-Date: 2020-08-07 19:53+0200\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
@ -1484,6 +1484,10 @@ msgstr ""
|
||||||
msgid "This team doesn't belong to the given bus."
|
msgid "This team doesn't belong to the given bus."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: apps/wei/forms/surveys/wei2020.py:26
|
||||||
|
msgid "Choose a word:"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: apps/wei/models.py:24 templates/wei/weiclub_info.html:23
|
#: apps/wei/models.py:24 templates/wei/weiclub_info.html:23
|
||||||
msgid "year"
|
msgid "year"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -1768,7 +1772,7 @@ msgstr ""
|
||||||
msgid "This user didn't give her/his caution check."
|
msgid "This user didn't give her/his caution check."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: apps/wei/views.py:917 apps/wei/views.py:970 apps/wei/views.py:980
|
#: apps/wei/views.py:917 apps/wei/views.py:971 apps/wei/views.py:981
|
||||||
#: templates/wei/survey.html:12 templates/wei/survey_closed.html:12
|
#: templates/wei/survey.html:12 templates/wei/survey_closed.html:12
|
||||||
#: templates/wei/survey_end.html:12
|
#: templates/wei/survey_end.html:12
|
||||||
msgid "Survey WEI"
|
msgid "Survey WEI"
|
||||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2020-08-07 14:17+0200\n"
|
"POT-Creation-Date: 2020-08-07 19:53+0200\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
@ -547,8 +547,7 @@ msgstr "début de l'adhésion"
|
||||||
#: apps/member/models.py:219
|
#: apps/member/models.py:219
|
||||||
msgid "Date from which the members can renew their membership."
|
msgid "Date from which the members can renew their membership."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Date à partir de laquelle les adhérents peuvent renouveler leur "
|
"Date à partir de laquelle les adhérents peuvent renouveler leur adhésion."
|
||||||
"adhésion."
|
|
||||||
|
|
||||||
#: apps/member/models.py:225 templates/member/club_info.html:28
|
#: apps/member/models.py:225 templates/member/club_info.html:28
|
||||||
msgid "membership end"
|
msgid "membership end"
|
||||||
|
@ -556,7 +555,9 @@ msgstr "fin de l'adhésion"
|
||||||
|
|
||||||
#: apps/member/models.py:226
|
#: apps/member/models.py:226
|
||||||
msgid "Maximal date of a membership, after which members must renew it."
|
msgid "Maximal date of a membership, after which members must renew it."
|
||||||
msgstr "Date maximale d'une fin d'adhésion, après laquelle les adhérents doivent la renouveler."
|
msgstr ""
|
||||||
|
"Date maximale d'une fin d'adhésion, après laquelle les adhérents doivent la "
|
||||||
|
"renouveler."
|
||||||
|
|
||||||
#: apps/member/models.py:258 apps/member/models.py:283
|
#: apps/member/models.py:258 apps/member/models.py:283
|
||||||
#: apps/note/models/notes.py:163
|
#: apps/note/models/notes.py:163
|
||||||
|
@ -1518,6 +1519,10 @@ msgstr "Sélectionnez les rôles qui vous intéressent."
|
||||||
msgid "This team doesn't belong to the given bus."
|
msgid "This team doesn't belong to the given bus."
|
||||||
msgstr "Cette équipe n'appartient pas à ce bus."
|
msgstr "Cette équipe n'appartient pas à ce bus."
|
||||||
|
|
||||||
|
#: apps/wei/forms/surveys/wei2020.py:26
|
||||||
|
msgid "Choose a word:"
|
||||||
|
msgstr "Choisissez un mot :"
|
||||||
|
|
||||||
#: apps/wei/models.py:24 templates/wei/weiclub_info.html:23
|
#: apps/wei/models.py:24 templates/wei/weiclub_info.html:23
|
||||||
msgid "year"
|
msgid "year"
|
||||||
msgstr "année"
|
msgstr "année"
|
||||||
|
@ -1814,7 +1819,7 @@ msgstr "Valider l'inscription WEI"
|
||||||
msgid "This user didn't give her/his caution check."
|
msgid "This user didn't give her/his caution check."
|
||||||
msgstr "Cet utilisateur n'a pas donné son chèque de caution."
|
msgstr "Cet utilisateur n'a pas donné son chèque de caution."
|
||||||
|
|
||||||
#: apps/wei/views.py:917 apps/wei/views.py:970 apps/wei/views.py:980
|
#: apps/wei/views.py:917 apps/wei/views.py:971 apps/wei/views.py:981
|
||||||
#: templates/wei/survey.html:12 templates/wei/survey_closed.html:12
|
#: templates/wei/survey.html:12 templates/wei/survey_closed.html:12
|
||||||
#: templates/wei/survey_end.html:12
|
#: templates/wei/survey_end.html:12
|
||||||
msgid "Survey WEI"
|
msgid "Survey WEI"
|
||||||
|
@ -2490,7 +2495,8 @@ msgstr "Cette facture est verrouillée et ne peut pas être supprimée."
|
||||||
msgid ""
|
msgid ""
|
||||||
"Are you sure you want to delete this invoice? This action can't be undone."
|
"Are you sure you want to delete this invoice? This action can't be undone."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Êtes-vous sûr de vouloir supprimer cette facture ? Cette action ne pourra pas être annulée."
|
"Êtes-vous sûr de vouloir supprimer cette facture ? Cette action ne pourra "
|
||||||
|
"pas être annulée."
|
||||||
|
|
||||||
#: templates/treasury/invoice_confirm_delete.html:26
|
#: templates/treasury/invoice_confirm_delete.html:26
|
||||||
msgid "Return to invoices list"
|
msgid "Return to invoices list"
|
||||||
|
|
|
@ -231,6 +231,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
CSRF_TOKEN = "{{ csrf_token }}";
|
CSRF_TOKEN = "{{ csrf_token }}";
|
||||||
|
$(".invalid-feedback").addClass("d-block");
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% block extrajavascript %}
|
{% block extrajavascript %}
|
||||||
|
|
Loading…
Reference in New Issue