Skip to content

Commit

Permalink
Add special registration type requiring a voucher
Browse files Browse the repository at this point in the history
ABy requiring a voucher to use a specific registration type, it can
become an "invite only" regtype. The cost set for it doesn't matter, it
can still be zero, but the attendee needs to be in posession of a
voucher to complete the registration. Not as convenient as using the
auto-approving ones like speaker or staff, but a lot more flexible.
  • Loading branch information
mhagander committed Dec 18, 2024
1 parent 83297a1 commit eaea411
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/confreg/registrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ Confirmed staff
: The attendee registering must use one of the accounts that
are listed as staff in the [conference configuration](configuring).

Must have voucher
: The registration must be done using a voucher. Vouchers in turn are tied to
a specific registration type, so using this makes it possible to say only
specific people can register as this type, by issuing them individual vouchers.

### Registration days <a name="days"></a>

Registration days are not a mandatory part of the system, but if they are used
Expand Down
6 changes: 5 additions & 1 deletion postgresqleu/confreg/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .models import PRIMARY_SPEAKER_PHOTO_RESOLUTION
from .util import send_conference_mail

from .regtypes import validate_special_reg_type
from .regtypes import validate_special_reg_type, validate_special_reg_type_form
from .twitter import get_all_conference_social_media
from postgresqleu.util.fields import UserModelChoiceField
from postgresqleu.util.widgets import StaticTextWidget
Expand Down Expand Up @@ -267,6 +267,10 @@ def clean(self):
if not found:
self._errors['regtype'] = 'Registration type "%s" requires at least one of the following additional options to be picked: %s' % (regtype, ", ".join([x.name for x in regtype.requires_option.all()]))

if cleaned_data['regtype'].specialtype:
for errfld, errmsg in validate_special_reg_type_form(cleaned_data['regtype'].specialtype, self.instance, cleaned_data):
self.add_error(errfld, errmsg)

if cleaned_data.get('additionaloptions', None) and 'regtype' in cleaned_data:
regtype = cleaned_data['regtype']
errs = []
Expand Down
25 changes: 24 additions & 1 deletion postgresqleu/confreg/regtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,37 @@ def confirm_manual_registration_setup(cleaned_data):
}


def validate_voucher_registration_form(reg, cleaned_data):
from .models import PrepaidVoucher

if cleaned_data.get('vouchercode', '') == '' or not PrepaidVoucher.objects.filter(conference=reg.conference, vouchervalue=cleaned_data['vouchercode']).exists():
yield ('regtype', 'This registration type is only available if you have a specific voucher for it.')


_specialregtypes['vch'] = {
'name': 'Requires specific voucher',
'formfunc': validate_voucher_registration_form,
}


special_reg_types = [(k, v['name']) for k, v in sorted(list(_specialregtypes.items()))]


def validate_special_reg_type(regtypename, reg):
if regtypename not in _specialregtypes:
raise ValidationError('Invalid registration type record. Internal error.')

_specialregtypes[regtypename]['func'](reg)
if 'func' in _specialregtypes[regtypename]:
_specialregtypes[regtypename]['func'](reg)


def validate_special_reg_type_form(regtypename, reg, cleaned_data):
if regtypename not in _specialregtypes:
raise ValidationError('Invalid registration type record. Internal error.')

if 'formfunc' in _specialregtypes[regtypename]:
return _specialregtypes[regtypename]['formfunc'](reg, cleaned_data) or ()
return ()


def confirm_special_reg_type(regtypename, reg):
Expand Down

0 comments on commit eaea411

Please sign in to comment.