mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 01:12:08 +01:00 
			
		
		
		
	one question by page
This commit is contained in:
		@@ -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,12 +54,12 @@ 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:
 | 
			
		||||
        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
 | 
			
		||||
 | 
			
		||||
@@ -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,7 +124,9 @@ class WEISurvey2023(WEISurvey):
 | 
			
		||||
 | 
			
		||||
    @transaction.atomic
 | 
			
		||||
    def form_valid(self, form):
 | 
			
		||||
        self.information.step += 1
 | 
			
		||||
        for question in WORDS:
 | 
			
		||||
            if question in form.cleaned_data:
 | 
			
		||||
                answer = form.cleaned_data[question]
 | 
			
		||||
                setattr(self.information, question, answer)
 | 
			
		||||
        self.save()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user