mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-11-26 18:37:12 +00:00
one question by page
This commit is contained in:
parent
9596aa7b8c
commit
e06e3b2972
@ -42,25 +42,11 @@ class WEISurveyForm2023(forms.Form):
|
|||||||
Survey form for the year 2023.
|
Survey form for the year 2023.
|
||||||
Members answer 20 question, from which we calculate the best associated bus.
|
Members answer 20 question, from which we calculate the best associated bus.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,**kwargs):
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
for question in WORDS:
|
|
||||||
self.fields[question] = forms.ChoiceField(
|
|
||||||
label=WORDS[question][0]+question,
|
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
information = WEISurveyInformation2023(registration)
|
information = WEISurveyInformation2023(registration)
|
||||||
if not information.seed:
|
|
||||||
information.seed = int(1000 * time.time())
|
|
||||||
information.save(registration)
|
|
||||||
registration._force_save = True
|
|
||||||
registration.save()
|
|
||||||
|
|
||||||
# if self.data:
|
# if self.data:
|
||||||
# for question in WORDS:
|
# for question in WORDS:
|
||||||
@ -68,12 +54,12 @@ class WEISurveyForm2023(forms.Form):
|
|||||||
# if self.is_valid():
|
# if self.is_valid():
|
||||||
# return
|
# return
|
||||||
|
|
||||||
# rng = Random(information.seed) # add someting if it's alwais the same
|
question = information.questions[information.step]
|
||||||
# questions = list(WORDS.keys())
|
print(information.step, question)
|
||||||
# rng.shuffle(questions)
|
self.fields[question] = forms.ChoiceField(
|
||||||
|
label=WORDS[question][0]+question,
|
||||||
# for question in questions:
|
widget=forms.RadioSelect(),
|
||||||
for question in WORDS:
|
)
|
||||||
answers = [(answer, WORDS[question][1][answer]) for answer in WORDS[question][1]]
|
answers = [(answer, WORDS[question][1][answer]) for answer in WORDS[question][1]]
|
||||||
self.fields[question].choices = answers
|
self.fields[question].choices = answers
|
||||||
|
|
||||||
@ -96,10 +82,19 @@ class WEISurveyInformation2023(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.
|
||||||
"""
|
"""
|
||||||
# Random seed that is stored at the first time to ensure that words are generated only once
|
|
||||||
seed = 0
|
step = 0
|
||||||
|
questions = list(WORDS.keys())
|
||||||
|
|
||||||
def __init__(self, registration):
|
def __init__(self, registration):
|
||||||
|
# print(hasattr(self,"questions"))
|
||||||
|
# if not hasattr(self, "questions"):
|
||||||
|
# rng = Random(int(1000 * time.time()))
|
||||||
|
# questions = list(WORDS.keys())
|
||||||
|
# rng.shuffle(questions)
|
||||||
|
# setattr(self, "questions", questions)
|
||||||
|
# print(questions)
|
||||||
|
|
||||||
for question in WORDS:
|
for question in WORDS:
|
||||||
setattr(self, str(question), None)
|
setattr(self, str(question), None)
|
||||||
super().__init__(registration)
|
super().__init__(registration)
|
||||||
@ -129,7 +124,9 @@ class WEISurvey2023(WEISurvey):
|
|||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
self.information.step += 1
|
||||||
for question in WORDS:
|
for question in WORDS:
|
||||||
|
if question in form.cleaned_data:
|
||||||
answer = form.cleaned_data[question]
|
answer = form.cleaned_data[question]
|
||||||
setattr(self.information, question, answer)
|
setattr(self.information, question, answer)
|
||||||
self.save()
|
self.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user