Skip to content

Commit

Permalink
Fix validations and upgrades
Browse files Browse the repository at this point in the history
There were a couple minor bugs with the forms, those should hopefully all be fixed now.
  • Loading branch information
kitsuta committed Mar 26, 2024
1 parent e1f7fcd commit 992d68f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
11 changes: 8 additions & 3 deletions magstock/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pockets.autolog import log

from uber.config import c
from uber.forms import (MagForm, HiddenBoolField, HiddenIntField, SelectAvailableField, MultiCheckbox)
from uber.forms import (CustomValidation, MagForm, HiddenBoolField, HiddenIntField, SelectAvailableField, MultiCheckbox)
from uber.custom_tags import popup_link, format_currency, pluralize, table_prices, email_to_link


Expand All @@ -35,6 +35,8 @@ def license_plate_desc(self):

@MagForm.form_mixin
class BadgeExtras:
new_or_changed_validation = CustomValidation()

camping_type = HiddenIntField('How are you camping?')
cabin_type = SelectAvailableField('Cabin Type',
choices=[(0, 'Please select a cabin type')] + c.CABIN_TYPE_OPTS,
Expand All @@ -52,6 +54,11 @@ def camping_type_desc(self):
'Car and RV camping is restricted to a field adjacent to the communal bathrooms. '
'Please review the information about camping options, including cabin type descriptions, '
'<a href="https://magstock.org/camping-info/" target="_blank">on our website</a>.')

@new_or_changed_validation.cabin_type
def cabin_sold_out(form, field):
if field.data in field.get_sold_out_list():
raise ValidationError(f"Sorry, we're sold out of {c.CABIN_TYPES[field.data].lower()}s!")


@MagForm.form_mixin
Expand Down Expand Up @@ -96,8 +103,6 @@ def get_optional_fields(self, attendee, is_admin=False):

@MagForm.form_mixin
class AdminConsents:
acknowledged_checkin_policy = HiddenBoolField()
waiver_consent = HiddenBoolField()
waiver_date = DateField('Date of Signature')


Expand Down
7 changes: 0 additions & 7 deletions magstock/model_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,3 @@ def waiver_consent(attendee):
attendee.legal_first_name + ' ' + attendee.legal_last_name)
elif attendee.waiver_date and attendee.waiver_date != datetime.utcnow().date():
return 'Your date of signature should be today'


@prereg_validation.Attendee
def cabin_sold_out(attendee):
if (attendee.is_new or attendee.orig_value_of('cabin_type') != attendee.cabin_type) \
and attendee.cabin_type and c.CABIN_AVAILABILITY_MATRIX[attendee.cabin_type] < 1:
return "The type of cabin you have selected is sold out."
8 changes: 4 additions & 4 deletions magstock/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def calc_camping_type_change(self, **kwargs):
return int(current_cost) * 100, (int(new_cost) * 100) - (int(current_cost) * 100)

def auto_update_receipt(self, params):
if params.get('camping_type') and params['camping_type'] != c.CABIN:
if params.get('camping_type') and int(params['camping_type']) != c.CABIN:
params['cabin_type'] = 0
return params

Expand Down Expand Up @@ -82,13 +82,13 @@ def available_cabin_types(self):
@property
def addons(self):
addon_list = []
if self.meal_plan:
if self.meal_plan and self.meal_plan != c.NO_FOOD:
addon_list.append(f'{self.meal_plan_label} (${c.MEAL_PLAN_PRICES[self.meal_plan]})')
if self.camping_type and self.camping_type == c.CABIN and self.cabin_type:
addon_list.append(f'{self.cabin_type_label} (${c.CABIN_TYPE_PRICES[self.cabin_type]})')
addon_list.append(f'{self.cabin_type_label}')
elif self.camping_type and int(c.CAMPING_TYPE_PRICES[self.camping_type]):
addon_list.append('{}{}{}'.format(self.camping_type_label,
' parking pass' if self.camping_type in [c.CAR, c.RV] else '',
' Parking Pass' if self.camping_type in [c.CAR, c.RV] else '',
' (${})'.format(c.CAMPING_TYPE_PRICES[self.camping_type])))
return addon_list

Expand Down
5 changes: 3 additions & 2 deletions magstock/templates/forms/attendee/admin_consents.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

{% block required %}
{{ super() }}
{{ consents.acknowledged_checkin_policy }}
{{ consents.waiver_consent }}

{{ form_macros.form_input(consents.acknowledged_checkin_policy, force_hidden=True)}}
{{ form_macros.form_input(consents.waiver_consent, force_hidden=True)}}

<div class="row g-sm-3">
<div class="col-12 col-sm-6">{{ form_macros.form_input(consents.waiver_signature, readonly=True) }}</div>
Expand Down
22 changes: 13 additions & 9 deletions magstock/templates/forms/attendee/badge_extras.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
closest_hide_selector='.row',
source_field_id=id_upgrade_prepend ~ "camping_type",
target_field_prepend=id_upgrade_prepend) }}
<div class="row g-sm-3">
<div class="col-12 col-sm-6">{{ form_macros.form_input(badge_extras.cabin_type, required=True, id=id_upgrade_prepend ~ "cabin_type") }}</div>
</div>

<div class="row g-sm-3">
{{ form_macros.card_select(badge_extras.meal_plan,
Expand All @@ -27,12 +30,22 @@
closest_hide_selector='.row',
source_field_id=id_upgrade_prepend ~ "meal_plan",
target_field_prepend=id_upgrade_prepend) }}

<div class="row g-sm-3">
<div class="col-12">{{ form_macros.form_input(badge_extras.meal_restrictions, id=id_upgrade_prepend ~ "meal_restrictions") }}</div>
</div>
{% elif not is_prereg_attendee %}
<div class="row g-sm-3">
<div class="col-12 col-sm-6">
<div class="form-text">{{ badge_extras.camping_type.label.text }}</div>
<div class="form-control-plaintext h5">{{ attendee.camping_type_label }}{% if attendee.camping_type != c.CABIN %}{{ macros.upgrade_button('camping-type') }}{% endif %}</div>
</div>
{% if attendee.camping_type == c.CABIN %}
<div class="col-12 col-sm-6">
<div class="form-text">{{ badge_extras.cabin_type.label.text }}</div>
<div class="form-control-plaintext h5">{{ attendee.cabin_type_label }}{% if attendee.cabin_type != c.PRIVATE %}{{ macros.upgrade_button('cabin-type') }}{% endif %}</div>
</div>
{% endif %}
</div>
<div class="row g-sm-3">
<div class="col-12 col-sm-6">
Expand All @@ -47,15 +60,6 @@
{% endif %}
</div>
{% endif %}

{% if not receipt or upgrade_modal %}
<div class="row g-sm-3">
<div class="col-12 col-sm-6">{{ form_macros.form_input(badge_extras.cabin_type, required=True, id=id_upgrade_prepend ~ "cabin_type") }}</div>
</div>
<div class="row g-sm-3">
<div class="col-12">{{ form_macros.form_input(badge_extras.meal_restrictions, id=id_upgrade_prepend ~ "meal_restrictions") }}</div>
</div>
{% endif %}
{% endblock %}

{% block upgrade_modal_js %}
Expand Down
3 changes: 3 additions & 0 deletions magstock/templates/forms/attendee/consents.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
<div class="row g-sm-3">
<div class="col-12">{{ form_macros.form_input(consents.waiver_consent) }}</div>
</div>
{% else %}
{{ form_macros.form_input(consents.acknowledged_checkin_policy, force_hidden=True)}}
{{ form_macros.form_input(consents.waiver_consent, force_hidden=True)}}
{% endif %}
{% endblock %}

0 comments on commit 992d68f

Please sign in to comment.