diff --git a/docs/settings.rst b/docs/settings.rst index 072d2ffe..86a142d3 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -76,13 +76,15 @@ Wafer's settings Otherwise, only users with associated public talks have public profiles. -``WAFER_REGISTRATION_FORM`` - A Django Form used for KV registration. - Used when ``WAFER_REGISTRATION_MODE`` is set set to ``'form'``. - ``WAFER_REGISTRATION_MODE`` - The mechanism wafer will use to decide if an attendee is registered. - The default is ``'ticket'`` for Quicket integration. + The mechanisms users will register for the conference, with. + Possible options are: + + ``'ticket'`` + For Quicket integration. The default. + + ``'custom'`` + For your own implementation. See ``WAFER_USER_IS_REGISTERED``. ``WAFER_REGISTRATION_OPEN`` A boolean flag. @@ -97,6 +99,12 @@ Wafer's settings The secret for the Quicket API. Used when ``WAFER_REGISTRATION_MODE`` is ``'ticket'``. +``WAFER_USER_IS_REGISTERED`` + A function, which takes a user, and determines if they have + registered for attendance at the conference. + It should return a boolean result. + The default function checks for a Quicket ticket. + ``WAFER_VIDEO`` A boolean flag. When ``True``, the default talk submission form will ask for a video diff --git a/wafer/management/commands/wafer_registered_attendees.py b/wafer/management/commands/wafer_registered_attendees.py index 27565c07..45fc9306 100644 --- a/wafer/management/commands/wafer_registered_attendees.py +++ b/wafer/management/commands/wafer_registered_attendees.py @@ -2,9 +2,7 @@ import sys from django.conf import settings -from django.contrib.auth.models import Group from django.core.management.base import BaseCommand -from django.utils.module_loading import import_string from wafer.users.models import UserProfile @@ -48,30 +46,6 @@ def details(self, person): return super(TicketRegisteredUserList, self).details(person) + details -class FormRegisteredUserList(RegisteredUserList): - def __init__(self): - self.group = Group.objects.get_by_natural_key('Registration') - form_class = import_string(settings.WAFER_REGISTRATION_FORM) - self.form = form_class() - - def fields(self): - return super(FormRegisteredUserList, self).fields() + tuple( - self.form.fields.keys()) - - def _iter_details(self, registration_data): - for field in self.form.fields.keys(): - item = registration_data.filter(key=field).first() - if item: - yield item.value - else: - yield None - - def details(self, person): - registration_data = person.kv.filter(group=self.group) - details = tuple(self._iter_details(registration_data)) - return super(FormRegisteredUserList, self).details(person) + details - - class Command(BaseCommand): help = "Dump attendee registration information" @@ -82,10 +56,8 @@ def handle(self, *args, **options): if settings.WAFER_REGISTRATION_MODE == 'ticket': user_list = TicketRegisteredUserList() - elif settings.WAFER_REGISTRATION_MODE == 'form': - user_list = FormRegisteredUserList() else: - raise NotImplemented('Unknown WAFER_REGISTRATION_MODE') + user_list = RegisteredUserList() csv_file.writerow(user_list.fields()) for row in user_list.attendees(): diff --git a/wafer/settings.py b/wafer/settings.py index 4b3a4baf..0e2b1348 100644 --- a/wafer/settings.py +++ b/wafer/settings.py @@ -280,11 +280,12 @@ # Set this to False to disable registration WAFER_REGISTRATION_OPEN = True -# Can be 'ticket' for Quicket tickets or 'form' for a classic form -WAFER_REGISTRATION_MODE = 'ticket' -# For REGISTRATION_MODE == 'form', the form to present -WAFER_REGISTRATION_FORM = 'wafer.users.forms.ExampleRegistrationForm' +# WAFER_REGISTRATION_MODE can be 'ticket' for Quicket tickets, or 'custom' if +# you implement your own registration system. +WAFER_REGISTRATION_MODE = 'ticket' +# WAFER_USER_IS_REGISTERED should return a boolean, when passed a Django user. +WAFER_USER_IS_REGISTERED = 'wafer.tickets.models.user_is_registered' # Allow registered and anonymous users to see registered users WAFER_PUBLIC_ATTENDEE_LIST = True diff --git a/wafer/tickets/models.py b/wafer/tickets/models.py index a297b3f0..c90a0fc9 100644 --- a/wafer/tickets/models.py +++ b/wafer/tickets/models.py @@ -25,3 +25,7 @@ class Ticket(models.Model): def __str__(self): return u'%s (%s)' % (self.barcode, self.email) + + +def user_is_registered(user): + return Ticket.objects.filter(user=user).exists() diff --git a/wafer/users/forms.py b/wafer/users/forms.py index 4bec77d7..1a9028f7 100644 --- a/wafer/users/forms.py +++ b/wafer/users/forms.py @@ -1,14 +1,11 @@ from django import forms -from django.conf import settings from django.contrib.auth import get_user_model from django.core.urlresolvers import reverse -from django.forms import fields -from django.utils.module_loading import import_string from django.utils.translation import ugettext as _ from crispy_forms.bootstrap import PrependedText from crispy_forms.helper import FormHelper -from crispy_forms.layout import Fieldset, Layout, Submit +from crispy_forms.layout import Submit from wafer.users.models import UserProfile @@ -46,41 +43,3 @@ def __init__(self, *args, **kwargs): class Meta: model = UserProfile exclude = ('user', 'kv') - - -def get_registration_form_class(): - return import_string(settings.WAFER_REGISTRATION_FORM) - - -class ExampleRegistrationForm(forms.Form): - debcamp = fields.BooleanField( - label=_('Plan to attend DebCamp'), required=False) - debconf = fields.BooleanField( - label=_('Plan to attend DebConf'), required=False) - require_sponsorship = fields.BooleanField( - label=_('Will require sponsorship'), required=False) - - def __init__(self, *args, **kwargs): - super(ExampleRegistrationForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - self.helper.layout = Layout( - Fieldset(_('Pre-Registration'), - 'debcamp', - 'debconf', - 'require_sponsorship')) - self.helper.add_input(Submit('submit', _('Save'))) - - @classmethod - def is_registered(cls, kv_data): - """ - Given a user's kv_data query, determine if they have registered to - attend. - """ - for item in kv_data.filter(key__in=('debcamp', 'debconf')): - if item.value is True: - return True - return False - - def initial_values(self, user): - """Set default values, based on the user""" - return {'debconf': True} diff --git a/wafer/users/models.py b/wafer/users/models.py index 71149ca9..5dc4d9c7 100644 --- a/wafer/users/models.py +++ b/wafer/users/models.py @@ -4,6 +4,7 @@ from django.db.models import Q from django.db.models.signals import post_save from django.utils.encoding import python_2_unicode_compatible +from django.utils.module_loading import import_string from django.core.validators import RegexValidator from libravatar import libravatar_url @@ -22,6 +23,7 @@ # Specification taken from https://support.twitter.com/articles/101299 TwitterValidator = RegexValidator('^[A-Za-z0-9_]{1,15}$', 'Incorrectly formatted twitter handle') +is_registered = import_string(settings.WAFER_USER_IS_REGISTERED) @python_2_unicode_compatible @@ -84,15 +86,7 @@ def display_name(self): return self.user.get_full_name() or self.user.username def is_registered(self): - from wafer.users.forms import get_registration_form_class - - if settings.WAFER_REGISTRATION_MODE == 'ticket': - return self.user.ticket.exists() - elif settings.WAFER_REGISTRATION_MODE == 'form': - form = get_registration_form_class() - return form.is_registered(self.kv) - raise NotImplemented('Invalid WAFER_REGISTRATION_MODE: %s' - % settings.WAFER_REGISTRATION_MODE) + return is_registered(self.user) is_registered.boolean = True diff --git a/wafer/users/templates/wafer.users/profile.html b/wafer/users/templates/wafer.users/profile.html index 33b94359..8222dba3 100644 --- a/wafer/users/templates/wafer.users/profile.html +++ b/wafer/users/templates/wafer.users/profile.html @@ -29,10 +29,8 @@
- {% blocktrans %} - You can come back and register, at any time (until registration closes). - {% endblocktrans %} -
-{% else %} -- {% blocktrans %} - Thank you for registering for {{ WAFER_CONFERENCE_NAME }}. - {% endblocktrans %} - {% if will_send_email %} - {% trans 'You should receive a confirmation e-mail, shortly.' %} - {% endif %} - {% blocktrans %} - You can come back and edit your registration, at any time (until - registration closes). - {% endblocktrans %} -
- {% if talks_open %} -- {% url 'wafer_talk_submit' as submit_url %} - {% blocktrans %} - Now would be a great time to - Submit a Talk Proposal. - {% endblocktrans %} -
- {% endif %} -{% endif %} -- - {% trans 'Back to my profile' %} - -
-{% endblock %} diff --git a/wafer/users/urls.py b/wafer/users/urls.py index 1dc6c066..014d9aee 100644 --- a/wafer/users/urls.py +++ b/wafer/users/urls.py @@ -2,7 +2,7 @@ from rest_framework import routers from wafer.users.views import (UsersView, ProfileView, EditProfileView, - EditUserView, RegistrationView, UserViewSet) + EditUserView, UserViewSet) router = routers.DefaultRouter() @@ -21,7 +21,4 @@ url(r'^(?P