1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-29 20:51:11 +02:00

Improve survey, comment code

This commit is contained in:
Yohann D'ANELLO
2020-04-20 01:26:53 +02:00
parent 473d3c3546
commit 16af9ac0ea
15 changed files with 274 additions and 67 deletions

View File

@ -8,29 +8,50 @@ from ...models import Bus
class WEISurveyForm2020(forms.Form):
"""
Survey form for the year 2020.
For now, that's only a Bus selector.
TODO: Do a better survey (later)
"""
bus = forms.ModelChoiceField(
Bus.objects,
)
def set_registration(self, registration):
"""
Filter the bus selector with the buses of the current WEI.
"""
self.fields["bus"].queryset = Bus.objects.filter(wei=registration.wei)
class WEISurveyInformation2020(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.
"""
chosen_bus_pk = None
chosen_bus_name = None
class WEISurvey2020(WEISurvey):
year = 2020
"""
Survey for the year 2020.
"""
@classmethod
def get_year(cls):
return 2020
def get_survey_information_class(self):
@classmethod
def get_survey_information_class(cls):
return WEISurveyInformation2020
def get_form_class(self):
return WEISurveyForm2020
def update_form(self, form):
"""
Filter the bus selector with the buses of the WEI.
"""
form.set_registration(self.registration)
def form_valid(self, form):
@ -39,13 +60,26 @@ class WEISurvey2020(WEISurvey):
self.information.chosen_bus_name = bus.name
self.save()
@staticmethod
def get_algorithm_class():
@classmethod
def get_algorithm_class(cls):
return WEISurveyAlgorithm2020
def is_complete(self) -> bool:
"""
The survey is complete once the bus is chosen.
"""
return self.information.chosen_bus_pk is not None
class WEISurveyAlgorithm2020(WEISurveyAlgorithm):
def get_survey_class(self):
"""
The algorithm class for the year 2020.
For now, the algorithm is quite simple: the selected bus is the chosen bus.
TODO: Improve this algorithm.
"""
@classmethod
def get_survey_class(cls):
return WEISurvey2020
def run_algorithm(self):