Skip to content

Commit

Permalink
Merge pull request #352 from CTPUG/other-registration-approaches
Browse files Browse the repository at this point in the history
Replace KV registration form with custom registration API
  • Loading branch information
drnlm committed Dec 16, 2017
2 parents 93a1cd8 + 228a876 commit 0d82aeb
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 298 deletions.
20 changes: 14 additions & 6 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
30 changes: 1 addition & 29 deletions wafer/management/commands/wafer_registered_attendees.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"

Expand All @@ -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():
Expand Down
9 changes: 5 additions & 4 deletions wafer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions wafer/tickets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
43 changes: 1 addition & 42 deletions wafer/users/forms.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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}
12 changes: 3 additions & 9 deletions wafer/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions wafer/users/templates/wafer.users/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
<ul class="float-right btn-group btn-group-vertical profile-links">
<li><a href="{% url 'wafer_user_edit' object.username %}" class="btn btn-secondary">{% trans 'Edit User' %}</a></li>
<li><a href="{% url 'wafer_user_edit_profile' object.username %}" class="btn btn-secondary">{% trans 'Edit Profile' %}</a></li>
{% if WAFER_REGISTRATION_OPEN %}
{% if WAFER_REGISTRATION_MODE == 'form' %}
{% url 'wafer_register_view' object.username as register_url %}
{% elif WAFER_REGISTRATION_MODE == 'ticket' and not profile.is_registered %}
{% if WAFER_REGISTRATION_OPEN and not profile.is_registered %}
{% if WAFER_REGISTRATION_MODE == 'ticket' %}
{% url 'wafer_ticket_claim' as register_url %}
{% endif %}
{% if register_url %}
Expand Down
12 changes: 0 additions & 12 deletions wafer/users/templates/wafer.users/registration/confirm_mail.txt

This file was deleted.

11 changes: 0 additions & 11 deletions wafer/users/templates/wafer.users/registration/form.html

This file was deleted.

45 changes: 0 additions & 45 deletions wafer/users/templates/wafer.users/registration/success.html

This file was deleted.

5 changes: 1 addition & 4 deletions wafer/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -21,7 +21,4 @@
url(r'^(?P<username>[\w.@+-]+)/edit_profile/$',
EditProfileView.as_view(),
name='wafer_user_edit_profile'),
url(r'^(?P<username>[\w.@+-]+)/register/$',
RegistrationView.as_view(),
name='wafer_register_view'),
]

0 comments on commit 0d82aeb

Please sign in to comment.