diff --git a/magwest/__init__.py b/magwest/__init__.py index 458a300..632d14c 100644 --- a/magwest/__init__.py +++ b/magwest/__init__.py @@ -6,10 +6,9 @@ from uber.utils import mount_site_sections, static_overrides from magwest._version import __version__ # noqa: F401 +from magwest.config import * -config = parse_config("magwest", Path(__file__).parents[0]) -c.include_plugin_config(config) mount_site_sections(config['module_root']) static_overrides(join(config['module_root'], 'static')) template_overrides(join(config['module_root'], 'templates')) diff --git a/magwest/config.py b/magwest/config.py new file mode 100644 index 0000000..b3f550f --- /dev/null +++ b/magwest/config.py @@ -0,0 +1,48 @@ +import math +from collections import defaultdict +from datetime import timedelta +from pathlib import Path +from markupsafe import Markup + +from uber.config import c, Config, dynamic, parse_config +from uber.menu import MenuItem +from uber.utils import localized_now + +config = parse_config("magwest", Path(__file__).parents[0]) +c.include_plugin_config(config) + +@Config.mixin +class ExtraConfig: + @property + def FORMATTED_BADGE_TYPES(self): + badge_types = [] + if c.AT_THE_CON and self.ONE_DAYS_ENABLED and self.ONE_DAY_BADGE_AVAILABLE: + badge_types.append({ + 'name': 'Single Day', + 'desc': 'Allows access to the convention for today. Can be upgraded to a weekend badge.', + 'value': c.ONE_DAY_BADGE, + 'price': c.ONEDAY_BADGE_PRICE + }) + badge_types.append({ + 'name': 'Attendee', + 'desc': 'Allows access to the convention for its duration.', + 'value': c.ATTENDEE_BADGE, + 'price': c.get_attendee_price() + }) + if c.GROUPS_ENABLED and c.BEFORE_GROUP_PREREG_TAKEDOWN: + badge_types.append({ + 'name': "Group Leader", + 'desc': Markup(f"Register a group of {c.MIN_GROUP_SIZE} people or more at ${c.GROUP_PRICE} per badge." + "

Please purchase badges for children 12 and under " + "separate from your group."), + 'value': c.PSEUDO_GROUP_BADGE, + 'price': c.GROUP_PRICE, + }) + for badge_type in c.BADGE_TYPE_PRICES: + badge_types.append({ + 'name': c.BADGES[badge_type], + 'desc': 'Donate extra to get an upgraded badge with perks.', + 'value': badge_type, + 'price': c.BADGE_TYPE_PRICES[badge_type] + }) + return badge_types \ No newline at end of file diff --git a/magwest/model_checks.py b/magwest/model_checks.py new file mode 100644 index 0000000..ce0d0f5 --- /dev/null +++ b/magwest/model_checks.py @@ -0,0 +1,28 @@ +from datetime import datetime + +from os.path import join + +from residue import CoerceUTF8 as UnicodeText +from sqlalchemy.types import Boolean, Date +from uber.api import AttendeeLookup +from uber.config import c, Config +from uber.decorators import cost_property, prereg_validation, presave_adjustment, validation +from uber.menu import MenuItem +from uber.models import Choice, DefaultColumn as Column, Session +from uber.jinja import template_overrides +from uber.utils import localized_now, valid_email, get_age_from_birthday + + +@prereg_validation.Attendee +def attendee_badge_under_13(attendee): + if c.AT_THE_CON: + return + + if not attendee.is_new and attendee.badge_status not in [c.PENDING_STATUS, c.AT_DOOR_PENDING_STATUS] \ + or attendee.unassigned_group_reg or attendee.valid_placeholder: + return + + if c.CHILD_BADGE in c.PREREG_BADGE_TYPES and attendee.birthdate and attendee.badge_type == c.ATTENDEE_BADGE and ( + get_age_from_birthday(attendee.birthdate, c.NOW_OR_AT_CON) < 13): + return ('badge_type', "If you will be 12 or younger at the start of {}, " + "please select the 12 and Under badge instead of an Attendee badge.".format(c.EVENT_NAME)) \ No newline at end of file diff --git a/magwest/templates/forms/prereg_fields.html b/magwest/templates/forms/prereg_fields.html new file mode 100644 index 0000000..8b990f2 --- /dev/null +++ b/magwest/templates/forms/prereg_fields.html @@ -0,0 +1,22 @@ +{%- import 'macros.html' as macros -%} +{% import 'forms/macros.html' as form_macros with context %} +{% set badge_extras = badge_extras or forms['badge_extras'] %} +{% set group_info = group_info or forms['group_info'] %} + +{% if c.FORMATTED_REG_TYPES and c.FORMATTED_REG_TYPES|length > 1 and not c.AT_THE_CON %} +
+ {{ form_macros.card_select(badge_extras.badge_type, + c.FORMATTED_REG_TYPES, disabled_opts=c.UNAVAILABLE_REG_TYPES, + target_field_id="badge_type", disabled_card_text="Unavailable", label="Registration Type") }} +
+{% else %} +
+ {{ form_macros.card_select(badge_extras.badge_type, + attendee.available_badge_type_opts, disabled_opts=c.SOLD_OUT_BADGE_TYPES, + target_field_id=id_upgrade_prepend ~ "badge_type") }} +
+{% endif %} +{% if c.GROUPS_ENABLED %} +{{ form_macros.toggle_fields_js(badge_extras.badge_type, [group_info.name, group_info.badges], + on_values=[c.PSEUDO_GROUP_BADGE], toggle_required=True) }} +{% endif %} \ No newline at end of file