mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 01:48:21 +02:00
WEI Survey (work in progress)
This commit is contained in:
10
apps/wei/forms/__init__.py
Normal file
10
apps/wei/forms/__init__.py
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from .registration import *
|
||||
from .surveys import *
|
||||
|
||||
__all__ = [
|
||||
'WEIForm', 'WEIRegistrationForm', 'WEIMembershipForm', 'BusForm', 'BusTeamForm',
|
||||
'WEISurvey', 'WEISurveyInformation', 'WEISurveyAlgorithm', 'CurrentSurvey',
|
||||
]
|
94
apps/wei/forms/registration.py
Normal file
94
apps/wei/forms/registration.py
Normal file
@ -0,0 +1,94 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from note_kfet.inputs import AmountInput, DatePickerInput, Autocomplete, ColorWidget
|
||||
|
||||
from wei.models import WEIClub, WEIRegistration, Bus, BusTeam, WEIMembership, WEIRole
|
||||
|
||||
|
||||
class WEIForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = WEIClub
|
||||
exclude = ('parent_club', 'require_memberships', 'membership_duration', )
|
||||
widgets = {
|
||||
"membership_fee_paid": AmountInput(),
|
||||
"membership_fee_unpaid": AmountInput(),
|
||||
"membership_start": DatePickerInput(),
|
||||
"membership_end": DatePickerInput(),
|
||||
"date_start": DatePickerInput(),
|
||||
"date_end": DatePickerInput(),
|
||||
}
|
||||
|
||||
|
||||
class WEIRegistrationForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = WEIRegistration
|
||||
exclude = ('wei', 'information_json', )
|
||||
widgets = {
|
||||
"user": Autocomplete(
|
||||
User,
|
||||
attrs={
|
||||
'api_url': '/api/user/',
|
||||
'name_field': 'username',
|
||||
'placeholder': 'Nom ...',
|
||||
},
|
||||
),
|
||||
"birth_date": DatePickerInput(),
|
||||
}
|
||||
|
||||
|
||||
class WEIMembershipForm(forms.ModelForm):
|
||||
roles = forms.ModelMultipleChoiceField(queryset=WEIRole.objects)
|
||||
|
||||
class Meta:
|
||||
model = WEIMembership
|
||||
fields = ('roles', 'bus', 'team',)
|
||||
widgets = {
|
||||
"bus": Autocomplete(
|
||||
Bus,
|
||||
attrs={
|
||||
'api_url': '/api/wei/bus/',
|
||||
'placeholder': 'Bus ...',
|
||||
}
|
||||
),
|
||||
"team": Autocomplete(
|
||||
BusTeam,
|
||||
attrs={
|
||||
'api_url': '/api/wei/team/',
|
||||
'placeholder': 'Équipe ...',
|
||||
}
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
class BusForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Bus
|
||||
fields = '__all__'
|
||||
widgets = {
|
||||
"wei": Autocomplete(
|
||||
WEIClub,
|
||||
attrs={
|
||||
'api_url': '/api/wei/club/',
|
||||
'placeholder': 'WEI ...',
|
||||
},
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
class BusTeamForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = BusTeam
|
||||
fields = '__all__'
|
||||
widgets = {
|
||||
"bus": Autocomplete(
|
||||
Bus,
|
||||
attrs={
|
||||
'api_url': '/api/wei/bus/',
|
||||
'placeholder': 'Bus ...',
|
||||
},
|
||||
),
|
||||
"color": ColorWidget(),
|
||||
}
|
12
apps/wei/forms/surveys/__init__.py
Normal file
12
apps/wei/forms/surveys/__init__.py
Normal file
@ -0,0 +1,12 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from .base import WEISurvey, WEISurveyInformation, WEISurveyAlgorithm
|
||||
from .wei2020 import WEISurvey2020
|
||||
|
||||
|
||||
__all__ = [
|
||||
'WEISurvey', 'WEISurveyInformation', 'WEISurveyAlgorithm', 'CurrentSurvey',
|
||||
]
|
||||
|
||||
CurrentSurvey = WEISurvey2020
|
61
apps/wei/forms/surveys/base.py
Normal file
61
apps/wei/forms/surveys/base.py
Normal file
@ -0,0 +1,61 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from wei.models import WEIClub, WEIRegistration
|
||||
|
||||
|
||||
class WEISurvey:
|
||||
year = None
|
||||
step = 0
|
||||
|
||||
def __init__(self, registration):
|
||||
self.registration = registration
|
||||
self.information = self.get_survey_information_class()(registration)
|
||||
|
||||
def get_wei(self):
|
||||
return WEIClub.objects.get(year=self.year)
|
||||
|
||||
def get_survey_information_class(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_form_class(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def update_form(self, form):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def get_algorithm_class():
|
||||
raise NotImplementedError
|
||||
|
||||
def form_valid(self, form):
|
||||
raise NotImplementedError
|
||||
|
||||
def save(self):
|
||||
self.information.save(self.registration)
|
||||
|
||||
def select_bus(self, bus_pk):
|
||||
self.information.selected_bus_pk = bus_pk
|
||||
|
||||
|
||||
class WEISurveyInformation:
|
||||
valid = False
|
||||
selected_bus_pk = None
|
||||
|
||||
def __init__(self, registration):
|
||||
self.__dict__.update(registration.information)
|
||||
|
||||
def save(self, registration):
|
||||
registration.information = self.__dict__
|
||||
registration.save()
|
||||
|
||||
|
||||
class WEISurveyAlgorithm:
|
||||
def get_survey_class(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_registrations(self):
|
||||
return WEIRegistration.objects.filter(wei__year=self.get_survey_class().year, first_year=True).all()
|
||||
|
||||
def run_algorithm(self):
|
||||
raise NotImplementedError
|
52
apps/wei/forms/surveys/wei2020.py
Normal file
52
apps/wei/forms/surveys/wei2020.py
Normal file
@ -0,0 +1,52 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django import forms
|
||||
|
||||
from .base import WEISurvey, WEISurveyInformation, WEISurveyAlgorithm
|
||||
from ...models import Bus
|
||||
|
||||
|
||||
class WEISurveyForm2020(forms.Form):
|
||||
bus = forms.ModelChoiceField(
|
||||
Bus.objects,
|
||||
)
|
||||
|
||||
def set_registration(self, registration):
|
||||
self.fields["bus"].queryset = Bus.objects.filter(wei=registration.wei)
|
||||
|
||||
|
||||
class WEISurveyInformation2020(WEISurveyInformation):
|
||||
chosen_bus_pk = None
|
||||
|
||||
|
||||
class WEISurvey2020(WEISurvey):
|
||||
year = 2020
|
||||
|
||||
def get_survey_information_class(self):
|
||||
return WEISurveyInformation2020
|
||||
|
||||
def get_form_class(self):
|
||||
return WEISurveyForm2020
|
||||
|
||||
def update_form(self, form):
|
||||
form.set_registration(self.registration)
|
||||
|
||||
def form_valid(self, form):
|
||||
self.information.chosen_bus_pk = form.cleaned_data["bus"].pk
|
||||
self.save()
|
||||
|
||||
@staticmethod
|
||||
def get_algorithm_class():
|
||||
return WEISurveyAlgorithm2020
|
||||
|
||||
|
||||
class WEISurveyAlgorithm2020(WEISurveyAlgorithm):
|
||||
def get_survey_class(self):
|
||||
return WEISurvey2020
|
||||
|
||||
def run_algorithm(self):
|
||||
for registration in self.get_registrations():
|
||||
survey = self.get_survey_class()(registration)
|
||||
survey.select_bus(survey.information.chosen_bus_pk)
|
||||
survey.save()
|
Reference in New Issue
Block a user