|
| 1 | +from indico.core.plugins import IndicoPlugin |
| 2 | +from indico.modules.events.registration.controllers import RegistrationFormMixin |
| 3 | +from indico.modules.events.registration.forms import RegistrationFormEditForm, _check_if_payment_required |
| 4 | +from indico_patcher import patch |
| 5 | +from wtforms.fields import DecimalField |
| 6 | +from wtforms.validators import Optional, NumberRange |
| 7 | +from wtforms.widgets import NumberInput |
| 8 | +from indico.core.db import db |
| 9 | + |
| 10 | +from indico_price_adjustments import _ |
| 11 | + |
| 12 | + |
| 13 | +@patch(RegistrationFormEditForm) |
| 14 | +class _RegistrationFormEditFormMixin: |
| 15 | + _price_fields = ('currency', 'base_price', 'extra_fee_for_guests') |
| 16 | + extra_fee_for_guests = DecimalField(_('Extra fee for guests'), |
| 17 | + [NumberRange(min=-999999999.99, max=999999999.99), Optional(), |
| 18 | + _check_if_payment_required], |
| 19 | + filters=[lambda x: x if x is not None else 0], |
| 20 | + widget=NumberInput(step='0.01'), |
| 21 | + description=_( |
| 22 | + 'An extra fee guests(non-logged-in users) have to pay when registering, negative amounts supported.')) |
| 23 | + |
| 24 | +@patch(RegistrationFormMixin) |
| 25 | +class _RegistrationFormMixin: |
| 26 | + extra_fee_for_guests = db.Column( |
| 27 | + db.Numeric(11, 2), # max. 999999999.99 |
| 28 | + nullable=False, |
| 29 | + default=0 |
| 30 | + ) |
| 31 | + |
| 32 | + |
| 33 | +class PriceAdjustmentsPlugin(IndicoPlugin): |
| 34 | + """Price Adjustments |
| 35 | +
|
| 36 | + Provides registration price adjustment options for non-logged-in users. |
| 37 | + """ |
| 38 | + configurable = False |
| 39 | + |
| 40 | + def init(self): |
| 41 | + super().init() |
| 42 | + # self.inject_bundle('main.css', WPManageRegistration) |
0 commit comments