one question by page

This commit is contained in:
bleizi 2023-08-26 23:47:10 +02:00
parent 9596aa7b8c
commit e06e3b2972
No known key found for this signature in database
GPG Key ID: D46D7E3364433208
1 changed files with 23 additions and 26 deletions

View File

@ -42,25 +42,11 @@ class WEISurveyForm2023(forms.Form):
Survey form for the year 2023.
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):
"""
Filter the bus selector with the buses of the current WEI.
"""
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:
# for question in WORDS:
@ -68,14 +54,14 @@ class WEISurveyForm2023(forms.Form):
# if self.is_valid():
# return
# rng = Random(information.seed) # add someting if it's alwais the same
# questions = list(WORDS.keys())
# rng.shuffle(questions)
# for question in questions:
for question in WORDS:
answers = [(answer, WORDS[question][1][answer]) for answer in WORDS[question][1]]
self.fields[question].choices = answers
question = information.questions[information.step]
print(information.step, question)
self.fields[question] = forms.ChoiceField(
label=WORDS[question][0]+question,
widget=forms.RadioSelect(),
)
answers = [(answer, WORDS[question][1][answer]) for answer in WORDS[question][1]]
self.fields[question].choices = answers
class WEIBusInformation2023(WEIBusInformation):
@ -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:
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):
# 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:
setattr(self, str(question), None)
super().__init__(registration)
@ -129,9 +124,11 @@ class WEISurvey2023(WEISurvey):
@transaction.atomic
def form_valid(self, form):
self.information.step += 1
for question in WORDS:
answer = form.cleaned_data[question]
setattr(self.information, question, answer)
if question in form.cleaned_data:
answer = form.cleaned_data[question]
setattr(self.information, question, answer)
self.save()
@classmethod