|
| 1 | +from crispy_forms.layout import Fieldset, Layout |
| 2 | +from django import forms |
| 3 | +from django.db.models import Q |
| 4 | + |
| 5 | +from kompassi.core.utils import horizontal_form_helper, indented_without_label |
| 6 | +from kompassi.labour.forms import AlternativeFormMixin, SignupForm |
| 7 | +from kompassi.labour.models import JobCategory, Signup |
| 8 | +from kompassi.zombies.programme.forms import ProgrammeSelfServiceForm |
| 9 | +from kompassi.zombies.programme.models import AlternativeProgrammeFormMixin |
| 10 | + |
| 11 | +from .models import SignupExtra |
| 12 | + |
| 13 | + |
| 14 | +class SignupExtraForm(forms.ModelForm): |
| 15 | + def __init__(self, *args, **kwargs): |
| 16 | + super().__init__(*args, **kwargs) |
| 17 | + self.helper = horizontal_form_helper() |
| 18 | + self.helper.form_tag = False |
| 19 | + self.helper.layout = Layout( |
| 20 | + "shift_type", |
| 21 | + indented_without_label("night_work"), |
| 22 | + Fieldset( |
| 23 | + "Lisätiedot", |
| 24 | + "shirt_size", |
| 25 | + "special_diet", |
| 26 | + "special_diet_other", |
| 27 | + "prior_experience", |
| 28 | + "free_text", |
| 29 | + ), |
| 30 | + ) |
| 31 | + |
| 32 | + class Meta: |
| 33 | + model = SignupExtra |
| 34 | + fields = ( |
| 35 | + "shift_type", |
| 36 | + "shirt_size", |
| 37 | + "special_diet", |
| 38 | + "special_diet_other", |
| 39 | + "night_work", |
| 40 | + "prior_experience", |
| 41 | + "free_text", |
| 42 | + ) |
| 43 | + |
| 44 | + widgets = dict( |
| 45 | + special_diet=forms.CheckboxSelectMultiple, |
| 46 | + ) |
| 47 | + |
| 48 | + |
| 49 | +class OrganizerSignupForm(forms.ModelForm, AlternativeFormMixin): |
| 50 | + def __init__(self, *args, **kwargs): |
| 51 | + kwargs.pop("event") |
| 52 | + admin = kwargs.pop("admin") |
| 53 | + |
| 54 | + if admin: |
| 55 | + raise AssertionError("must not be admin") |
| 56 | + |
| 57 | + super().__init__(*args, **kwargs) |
| 58 | + |
| 59 | + self.helper = horizontal_form_helper() |
| 60 | + self.helper.form_tag = False |
| 61 | + self.helper.layout = Layout( |
| 62 | + Fieldset( |
| 63 | + "Tehtävän tiedot", |
| 64 | + "job_title", |
| 65 | + ), |
| 66 | + ) |
| 67 | + |
| 68 | + self.fields["job_title"].help_text = "Mikä on tehtäväsi vastaavana? Printataan badgeen." |
| 69 | + # self.fields['job_title'].required = True |
| 70 | + |
| 71 | + class Meta: |
| 72 | + model = Signup |
| 73 | + fields = ("job_title",) |
| 74 | + |
| 75 | + widgets = dict( |
| 76 | + job_categories=forms.CheckboxSelectMultiple, |
| 77 | + special_diet=forms.CheckboxSelectMultiple, |
| 78 | + ) |
| 79 | + |
| 80 | + def get_excluded_m2m_field_defaults(self): |
| 81 | + return dict(job_categories=JobCategory.objects.filter(event__slug="frostbite2026", name="Vastaava")) |
| 82 | + |
| 83 | + |
| 84 | +class OrganizerSignupExtraForm(forms.ModelForm, AlternativeFormMixin): |
| 85 | + def __init__(self, *args, **kwargs): |
| 86 | + super().__init__(*args, **kwargs) |
| 87 | + self.helper = horizontal_form_helper() |
| 88 | + self.helper.form_tag = False |
| 89 | + self.helper.layout = Layout( |
| 90 | + Fieldset( |
| 91 | + "Lisätiedot", |
| 92 | + # "shirt_size", |
| 93 | + "special_diet", |
| 94 | + "special_diet_other", |
| 95 | + ), |
| 96 | + ) |
| 97 | + |
| 98 | + class Meta: |
| 99 | + model = SignupExtra |
| 100 | + fields = ( |
| 101 | + # "shirt_size", |
| 102 | + "special_diet", |
| 103 | + "special_diet_other", |
| 104 | + ) |
| 105 | + |
| 106 | + widgets = dict( |
| 107 | + special_diet=forms.CheckboxSelectMultiple, |
| 108 | + ) |
| 109 | + |
| 110 | + def get_excluded_field_defaults(self): |
| 111 | + return dict( |
| 112 | + shift_type="none", |
| 113 | + free_text="Syötetty käyttäen vastaavan ilmoittautumislomaketta", |
| 114 | + ) |
| 115 | + |
| 116 | + |
| 117 | +class SpecialistSignupForm(SignupForm, AlternativeFormMixin): |
| 118 | + def get_job_categories_query(self, event, admin=False): |
| 119 | + if admin: |
| 120 | + raise AssertionError("must not be admin") |
| 121 | + |
| 122 | + return Q(event__slug="frostbite2026", public=False) & ~Q(slug="vastaava") |
| 123 | + |
| 124 | + def get_excluded_field_defaults(self): |
| 125 | + return dict( |
| 126 | + notes="Syötetty käyttäen jälki-ilmoittautumislomaketta", |
| 127 | + ) |
| 128 | + |
| 129 | + |
| 130 | +class SpecialistSignupExtraForm(SignupExtraForm, AlternativeFormMixin): |
| 131 | + def __init__(self, *args, **kwargs): |
| 132 | + super().__init__(*args, **kwargs) |
| 133 | + self.helper = horizontal_form_helper() |
| 134 | + self.helper.form_tag = False |
| 135 | + self.helper.layout = Layout( |
| 136 | + "shift_type", |
| 137 | + indented_without_label("night_work"), |
| 138 | + Fieldset( |
| 139 | + "Lisätiedot", |
| 140 | + "shirt_size", |
| 141 | + "special_diet", |
| 142 | + "special_diet_other", |
| 143 | + "prior_experience", |
| 144 | + "free_text", |
| 145 | + ), |
| 146 | + ) |
| 147 | + |
| 148 | + class Meta: |
| 149 | + model = SignupExtra |
| 150 | + fields = ( |
| 151 | + "shift_type", |
| 152 | + "shirt_size", |
| 153 | + "special_diet", |
| 154 | + "special_diet_other", |
| 155 | + "night_work", |
| 156 | + "prior_experience", |
| 157 | + "free_text", |
| 158 | + ) |
| 159 | + |
| 160 | + widgets = dict( |
| 161 | + special_diet=forms.CheckboxSelectMultiple, |
| 162 | + ) |
| 163 | + |
| 164 | + |
| 165 | +class ProgrammeForm(ProgrammeSelfServiceForm, AlternativeProgrammeFormMixin): |
| 166 | + def __init__(self, *args, **kwargs): |
| 167 | + super().__init__(*args, **kwargs) |
| 168 | + |
| 169 | + def get_excluded_field_defaults(self): |
| 170 | + return dict() |
| 171 | + |
| 172 | + |
| 173 | +class AfterpartyParticipationSurvey(forms.ModelForm): |
| 174 | + def __init__(self, *args, **kwargs): |
| 175 | + kwargs.pop("event") |
| 176 | + |
| 177 | + super().__init__(*args, **kwargs) |
| 178 | + |
| 179 | + self.helper = horizontal_form_helper() |
| 180 | + self.helper.form_tag = False |
| 181 | + |
| 182 | + @classmethod |
| 183 | + def get_instance_for_event_and_person(cls, event, person): |
| 184 | + return SignupExtra.objects.get( |
| 185 | + event=event, |
| 186 | + person=person, |
| 187 | + is_active=True, |
| 188 | + ) |
| 189 | + |
| 190 | + class Meta: |
| 191 | + model = SignupExtra |
| 192 | + fields = ( |
| 193 | + "afterparty_participation", |
| 194 | + "pick_your_poison", |
| 195 | + "special_diet", |
| 196 | + "special_diet_other", |
| 197 | + ) |
| 198 | + widgets = dict( |
| 199 | + special_diet=forms.CheckboxSelectMultiple, |
| 200 | + pick_your_poison=forms.CheckboxSelectMultiple, |
| 201 | + ) |
| 202 | + |
| 203 | + |
| 204 | +class AccommodationSurvey(forms.ModelForm): |
| 205 | + def __init__(self, *args, **kwargs): |
| 206 | + kwargs.pop("event") |
| 207 | + |
| 208 | + super().__init__(*args, **kwargs) |
| 209 | + |
| 210 | + self.helper = horizontal_form_helper() |
| 211 | + self.helper.form_tag = False |
| 212 | + |
| 213 | + @classmethod |
| 214 | + def get_instance_for_event_and_person(cls, event, person): |
| 215 | + return SignupExtra.objects.get( |
| 216 | + event=event, |
| 217 | + person=person, |
| 218 | + is_active=True, |
| 219 | + ) |
| 220 | + |
| 221 | + class Meta: |
| 222 | + model = SignupExtra |
| 223 | + fields = ("accommodation",) |
0 commit comments