Skip to content

Commit

Permalink
Merge pull request #178 from magfest/stock2024
Browse files Browse the repository at this point in the history
Convert dealer reg to new form system
  • Loading branch information
kitsuta authored Mar 14, 2024
2 parents 8d60de1 + cb69ccb commit 2b72ad8
Show file tree
Hide file tree
Showing 24 changed files with 290 additions and 305 deletions.
1 change: 1 addition & 0 deletions magstock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from . import models # noqa: F401,E402,F403
from . import model_checks # noqa: F401,E402,F403
from . import receipt_items # noqa: F401
from . import forms # noqa: F401

mount_site_sections(config['module_root'])
static_overrides(join(config['module_root'], 'static'))
Expand Down
16 changes: 16 additions & 0 deletions magstock/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@

@Config.mixin
class ExtraConfig:
@property
def FORMATTED_CAMPING_TYPES(self):
# Returns camping type options for the 'card_select' form macro.

return [
{'name': 'Tent', 'icon': '', 'link': '', 'value': c.TENT, 'price': 0,
'desc': 'Included in your registration! Tent camping is first come, first serve.'},
{'name': 'Car', 'icon': '', 'link': '', 'value': c.CAR, 'price': c.CAMPING_TYPE_PRICES[c.CAR],
'desc': 'Price is per vehicle.'},
{'name': 'RV', 'icon': '', 'link': '', 'value': c.RV, 'price': c.CAMPING_TYPE_PRICES[c.RV],
'desc': 'Price is per vehicle, and there are no power or sewage hookups.'},
{'name': 'Cabin ($600+)', 'icon': '', 'link': '', 'value': c.CABIN,
'price': 0,
'desc': 'Select a cabin option below. Cabins are limited availability.'}
]

@property
def CAMPING_TYPE_BUTTONS(self):
# With apologies to future-me
Expand Down
96 changes: 96 additions & 0 deletions magstock/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import cherrypy

from markupsafe import Markup
from wtforms import (BooleanField, DateField, EmailField, Form, FormField,
HiddenField, SelectField, SelectMultipleField, IntegerField,
StringField, TelField, validators, TextAreaField)
from wtforms.validators import ValidationError, StopValidation
from wtforms.widgets import html_params
from pockets.autolog import log

from uber.config import c
from uber.forms import (AddressForm, NumberInputGroup, MagForm, IntSelect, SwitchInput, HiddenIntField, SelectAvailableField, CustomValidation)
from uber.custom_tags import popup_link, format_currency, pluralize, table_prices, email_to_link


@MagForm.form_mixin
class PersonalInfo:
license_plate = StringField('License Plate #', render_kw={'placeholder': 'XXX-XXXX'})
badge_printed_name = HiddenField('Badge Printed Name (Unused)')

def get_optional_fields(self, attendee, is_admin=False):
optional_list = self.super_get_optional_fields(attendee, is_admin)

# This field is disabled/hidden, so it's never required
optional_list.append('badge_printed_name')
return optional_list

def onsite_contact_label(self):
return "MAGBuddy"

def license_plate_desc(self):
return ("Get through registration faster on-site! If you don't know which vehicle you'll be using, "
"you can come back and update this later.")


@MagForm.form_mixin
class BadgeExtras:
camping_type = HiddenIntField('How are you camping?')
cabin_type = SelectAvailableField('Cabin Type',
choices=[(0, 'Please select a cabin type')] + c.CABIN_TYPE_OPTS,
default=0, coerce=int,
sold_out_list_func=lambda: [cabin for cabin in c.CABIN_AVAILABILITY_MATRIX
if c.CABIN_AVAILABILITY_MATRIX[cabin] < 1])
# Meal tickets go here

def camping_type_desc(self):
return Markup(
'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>.')


@MagForm.form_mixin
class Consents:
acknowledged_checkin_policy = BooleanField(
Markup('<strong>I acknowledge that there is NO early check-in and if I show up on Wednesday night '
'then I will probably be asked to leave the campground.</strong>'),
validators=[validators.InputRequired("You must acknowledge that early check-in is not possible.")])
waiver_signature = StringField(
'Electronic Signature',
validators=[validators.DataRequired("You must sign your full legal name to consent to the waiver.")])
waiver_date_display = DateField('Date of Signature', render_kw={'disabled': True})
waiver_date = HiddenField('Date of Signature (UTC)',
validators=[validators.DataRequired("No date of signature."
"Please refresh the page or contact us.")])
waiver_consent = BooleanField(
Markup('<strong>Yes</strong>, I understand that checking this box constitutes a legal signature '
'confirming that I acknowledge and agree to the above waiver.'),
validators=[validators.InputRequired("You must check the waiver consent checkbox.")])

def get_non_admin_locked_fields(self, attendee):
if attendee.needs_pii_consent:
return []

return ['pii_consent', 'acknowledged_checkin_policy', 'waiver_date', 'waiver_signature', 'waiver_consent']

def get_optional_fields(self, attendee, is_admin=False):
optional_fields = self.super_get_optional_fields(attendee, is_admin)

if (attendee.is_new or attendee.badge_status == c.PENDING_STATUS) or (
attendee.valid_placeholder and cherrypy.request.method == 'POST'):
optional_fields.extend(['acknowledged_checkin_policy', 'waiver_date',
'waiver_signature', 'waiver_consent'])

return optional_fields


@MagForm.form_mixin
class PreregOtherInfo:
first_name = HiddenField('First Name')
last_name = HiddenField('Last Name')
acknowledged_checkin_policy = Consents.acknowledged_checkin_policy
waiver_signature = Consents.waiver_signature
waiver_date_display = Consents.waiver_date_display
waiver_date = Consents.waiver_date
waiver_consent = Consents.waiver_consent
25 changes: 2 additions & 23 deletions magstock/model_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,15 @@
from uber.jinja import template_overrides
from uber.utils import add_opt, mount_site_sections, static_overrides

@validation.Attendee
def camping_checks(attendee):
if not attendee.placeholder and not attendee.camping_type:
return 'Please tell us how you are camping'


@prereg_validation.Attendee
def waiver_consent(attendee):
if attendee.is_new or attendee.placeholder:
if not attendee.waiver_signature:
return 'You must sign your full legal name to consent to the waiver'
elif attendee.waiver_signature != attendee.legal_first_name + ' ' + attendee.legal_last_name:
if attendee.waiver_signature and attendee.waiver_signature != attendee.legal_first_name + ' ' + attendee.legal_last_name:
return 'Your waiver signature must match your full legal name, {}'.format(
attendee.legal_first_name + ' ' + attendee.legal_last_name)
elif not attendee.waiver_consent:
return 'You must check the waiver consent checkbox'
elif attendee.waiver_date != datetime.utcnow().date():
elif attendee.waiver_date and attendee.waiver_date != datetime.utcnow().date():
return 'Your date of signature should be today'


@prereg_validation.Attendee
def no_early_checkin(attendee):
if (attendee.is_new or attendee.placeholder) and not attendee.acknowledged_checkin_policy:
return 'You must acknowledge that early check-in is not possible.'


@validation.Attendee
def must_pick_cabin(attendee):
if attendee.camping_type == c.CABIN and not attendee.cabin_type:
return 'Please select a cabin type.'


@prereg_validation.Attendee
Expand Down
9 changes: 7 additions & 2 deletions magstock/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def calc_meal_ticket_change(self, **kwargs):
new_cost = int(kwargs['dinner_tickets']) * c.FOOD_PRICE * 100

return current_cost, new_cost - current_cost

def calc_camping_type_change(self, **kwargs):
if 'camping_type' in kwargs:
if kwargs['camping_type'] == c.CABIN:
Expand All @@ -54,7 +54,12 @@ def calc_camping_type_change(self, **kwargs):
new_cost = 0

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:
params['cabin_type'] = 0
return params

@presave_adjustment
def no_cabin_if_not_cabin_camping(self):
if self.camping_type != c.CABIN:
Expand Down
63 changes: 63 additions & 0 deletions magstock/templates/forms/attendee/badge_extras.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% extends 'uber/templates/forms/attendee/badge_extras.html' %}

{% set id_upgrade_prepend = "upgrade_" if upgrade_modal else "" %}

{% block badge_type %}
{{ super() }}
{{ badge_extras.camping_type(id=id_upgrade_prepend ~ "camping_type") }}

{% if not receipt or upgrade_modal %}
<div class="row g-sm-3">
{{ form_macros.card_select(badge_extras.camping_type,
c.FORMATTED_CAMPING_TYPES, disabled_opts=[],
target_field_id=id_upgrade_prepend ~ "camping_type") }}
</div>
{{ form_macros.toggle_fields_js(badge_extras.camping_type, [badge_extras.cabin_type], on_values=["267506057"], toggle_required=True,
closest_hide_selector='.row',
source_field_id=id_upgrade_prepend ~ "camping_type",
target_field_prepend=id_upgrade_prepend) }}
{% 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>
</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>
{% endif %}
{% endblock %}

{% block upgrade_modal_js %}
{{ super() }}

{% if upgrade_modal %}
<script type="text/javascript">
$(function () {
var lastCampingType; // Still hate JavaScript
$("#upgrade_camping_type").on('change', function() {
if (lastCampingType !== undefined && this.value == lastCampingType) {
return;
} else {
if (lastCampingType == "{{ c.CABIN }}" && this.value != "{{ c.CABIN }}") {
updateReceiptPreview('cabin_type', '');
}
lastCampingType = this.value;
}
updateReceiptPreview('camping_type', this.value);
});

var lastCabinType;
$("#upgrade_cabin_type").on('change', function() {
if ($("#upgrade_camping_type").val() == "{{ c.CABIN }}") {
updateReceiptPreview('cabin_type', this.value);
}
})
});
</script>
{% endif %}
{% endblock %}
32 changes: 32 additions & 0 deletions magstock/templates/forms/attendee/consents.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends 'uber/templates/forms/attendee/consents.html' %}

{% block required %}
{{ super() }}

{% if not attendee.is_new and attendee.badge_status != c.PENDING_STATUS %}
<div class="row g-sm-3">
<div class="col-12">{{ form_macros.form_input(consents.acknowledged_checkin_policy) }}</div>
</div>

<div class="row mt-3">
<div class="col-12">
<p class="text-center">
<strong>We require all attendees to sign a waiver before registering.</strong> Please
{{ macros.popup_link("../static_views/waiver.html", "view the waiver here") }}, then sign below.
</p>
</div>
</div>

<div class="row g-sm-3">
<div class="col-12 col-sm-6">{{ form_macros.form_input(consents.waiver_signature) }}</div>
<div class="col-12 col-sm-6">
{{ form_macros.form_input(consents.waiver_date_display, value=now()|datetime_local("%Y-%m-%d")) }}
{{ form_macros.form_input(consents.waiver_date, value=now()|datetime("%Y-%m-%d")) }}
</div>
</div>

<div class="row g-sm-3">
<div class="col-12">{{ form_macros.form_input(consents.waiver_consent) }}</div>
</div>
{% endif %}
{% endblock %}
9 changes: 9 additions & 0 deletions magstock/templates/forms/attendee/other_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'uber/templates/forms/attendee/other_info.html' %}

{% block accessibility %}
{% if not admin_area %}
<div class="row mt-3 mb-3">
<div class="col-12">For accessibility-related needs or questions, please contact {{ "[email protected]"|email_to_link }}.</div>
</div>
{% endif %}
{% endblock %}
13 changes: 13 additions & 0 deletions magstock/templates/forms/attendee/personal_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends 'uber/templates/forms/attendee/personal_info.html' %}

{% block address %}
{% if attendee.badge_type == c.PSEUDO_DEALER_BADGE %}
{# Hack to get around WTForms requiring a selection for choice fields #}
<input type="hidden" name="cabin_type" value="0" />
{% endif %}

<div class="row g-sm-3">
{{ super() }}
<div class="col-12 col-sm-6">{{ form_macros.form_input(personal_info.license_plate) }}</div>
</div>
{% endblock %}
34 changes: 34 additions & 0 deletions magstock/templates/forms/attendee/prereg_other_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends 'uber/templates/forms/attendee/prereg_other_info.html' %}

{% block prereg_extras %}
{{ super() }}

<div class="row g-sm-3">
<div class="col-12">{{ form_macros.form_input(other_info.acknowledged_checkin_policy) }}</div>
</div>

<div class="row mt-3">
<div class="col-12">
<p class="text-center">
<strong>We require all attendees to sign a waiver before registering.</strong> Please
{{ macros.popup_link("../static_views/waiver.html", "view the waiver here") }}, then sign below.
</p>
</div>
</div>

{# The waiver validation needs to check first/last name, so they need to exist on this form. #}
{{ other_info.first_name }}
{{ other_info.last_name }}

<div class="row g-sm-3">
<div class="col-12 col-sm-6">{{ form_macros.form_input(other_info.waiver_signature) }}</div>
<div class="col-12 col-sm-6">
{{ form_macros.form_input(other_info.waiver_date_display, value=now()|datetime_local("%Y-%m-%d")) }}
{{ form_macros.form_input(other_info.waiver_date, value=now()|datetime("%Y-%m-%d")) }}
</div>
</div>

<div class="row g-sm-3">
<div class="col-12">{{ form_macros.form_input(other_info.waiver_consent) }}</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion magstock/templates/guests/band_agreement.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "guests/band_agreement.html" %}
{% extends "uber/templates/guests/band_agreement.html" %}

{% block band_text_merch_inner %}
Tables will be available in our concert tent throughout the weekend for performers' use.
Expand Down
2 changes: 1 addition & 1 deletion magstock/templates/guests/guest_agreement.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "guests/guest_agreement.html" %}
{% extends "uber/templates/guests/guest_agreement.html" %}

{% block guest_text_merch_inner %}
Tables will be available in our concert tent throughout the weekend for guests' use.
Expand Down
2 changes: 1 addition & 1 deletion magstock/templates/magstock/addons.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html" %}{% set admin_area=True %}
{% extends "uber/templates/base.html" %}{% set admin_area=True %}
{% block title %}Parties{% endblock %}
{% block content %}

Expand Down
2 changes: 1 addition & 1 deletion magstock/templates/magstock/campsite_assignments.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html" %}{% set admin_area=True %}
{% extends "uber/templates/base.html" %}{% set admin_area=True %}
{% block title %}Magstock Campsites{% endblock %}
{% block content %}

Expand Down
2 changes: 1 addition & 1 deletion magstock/templates/magstock/food_consumers.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html" %}{% set admin_area=True %}
{% extends "uber/templates/base.html" %}{% set admin_area=True %}
{% block title %}Magstock Food Report{% endblock %}
{% block content %}
<h2 class="center">MAGStock Food Report</h2>
Expand Down
2 changes: 1 addition & 1 deletion magstock/templates/magstock/grouped.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html" %}{% set admin_area=True %}
{% extends "uber/templates/base.html" %}{% set admin_area=True %}
{% block title %}Parties{% endblock %}
{% block content %}

Expand Down
2 changes: 1 addition & 1 deletion magstock/templates/magstock/parking.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html" %}{% set admin_area=True %}
{% extends "uber/templates/base.html" %}{% set admin_area=True %}
{% block title %}Magstock Vehicles{% endblock %}
{% block content %}

Expand Down
2 changes: 1 addition & 1 deletion magstock/templates/preregistration/closed.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "./preregistration/preregbase.html" %}
{% extends "uber/templates/preregistration/preregbase.html" %}
{% block title %}Preregistration is now closed{% endblock %}
{% block backlink %}{% endblock %}
{% block content %}
Expand Down
Loading

0 comments on commit 2b72ad8

Please sign in to comment.