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. 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,14 +54,14 @@ 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
class WEIBusInformation2023(WEIBusInformation): 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: 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,9 +124,11 @@ 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:
answer = form.cleaned_data[question] if question in form.cleaned_data:
setattr(self.information, question, answer) answer = form.cleaned_data[question]
setattr(self.information, question, answer)
self.save() self.save()
@classmethod @classmethod