Merge branch 'pluggable_profile'
This commit is contained in:
commit
a65b7935a9
4 changed files with 73 additions and 85 deletions
|
@ -132,14 +132,6 @@ def ProductsForm(category, products):
|
|||
return ProductsForm
|
||||
|
||||
|
||||
class ProfileForm(forms.ModelForm):
|
||||
''' A form for requesting badge and profile information. '''
|
||||
|
||||
class Meta:
|
||||
model = rego.BadgeAndProfile
|
||||
exclude = ['attendee']
|
||||
|
||||
|
||||
class VoucherForm(forms.Form):
|
||||
voucher = forms.CharField(
|
||||
label="Voucher code",
|
||||
|
|
30
registrasion/migrations/0011_auto_20160401_0943.py
Normal file
30
registrasion/migrations/0011_auto_20160401_0943.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.2 on 2016-04-01 09:43
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('registrasion', '0010_auto_20160330_2342'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='AttendeeProfileBase',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('attendee', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='registrasion.Attendee')),
|
||||
],
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='badgeandprofile',
|
||||
name='attendee',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='BadgeAndProfile',
|
||||
),
|
||||
]
|
|
@ -41,82 +41,20 @@ class Attendee(models.Model):
|
|||
highest_complete_category = models.IntegerField(default=0)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class BadgeAndProfile(models.Model):
|
||||
''' Information for an attendee's badge and related preferences '''
|
||||
class AttendeeProfileBase(models.Model):
|
||||
''' Information for an attendee's badge and related preferences.
|
||||
Subclass this in your Django site to ask for attendee information in your
|
||||
registration progess.
|
||||
'''
|
||||
|
||||
def __str__(self):
|
||||
return "Badge for: %s of %s" % (self.name, self.company)
|
||||
|
||||
@staticmethod
|
||||
def get_instance(attendee):
|
||||
''' Returns either None, or the instance that belongs
|
||||
to this attendee. '''
|
||||
try:
|
||||
return BadgeAndProfile.objects.get(attendee=attendee)
|
||||
except ObjectDoesNotExist:
|
||||
return None
|
||||
|
||||
def save(self):
|
||||
if not self.name_per_invoice:
|
||||
self.name_per_invoice = self.name
|
||||
super(BadgeAndProfile, self).save()
|
||||
@classmethod
|
||||
def name_field(cls):
|
||||
''' This is used to pre-fill the attendee's name from the
|
||||
speaker profile. If it's None, that functionality is disabled. '''
|
||||
return None
|
||||
|
||||
attendee = models.OneToOneField(Attendee, on_delete=models.CASCADE)
|
||||
|
||||
# Things that appear on badge
|
||||
name = models.CharField(
|
||||
verbose_name="Your name (for your conference nametag)",
|
||||
max_length=64,
|
||||
help_text="Your name, as you'd like it to appear on your badge. ",
|
||||
)
|
||||
company = models.CharField(
|
||||
max_length=64,
|
||||
help_text="The name of your company, as you'd like it on your badge",
|
||||
blank=True,
|
||||
)
|
||||
free_text_1 = models.CharField(
|
||||
max_length=64,
|
||||
verbose_name="Free text line 1",
|
||||
help_text="A line of free text that will appear on your badge. Use "
|
||||
"this for your Twitter handle, IRC nick, your preferred "
|
||||
"pronouns or anything else you'd like people to see on "
|
||||
"your badge.",
|
||||
blank=True,
|
||||
)
|
||||
free_text_2 = models.CharField(
|
||||
max_length=64,
|
||||
verbose_name="Free text line 2",
|
||||
blank=True,
|
||||
)
|
||||
|
||||
# Other important Information
|
||||
name_per_invoice = models.CharField(
|
||||
verbose_name="Your legal name (for invoicing purposes)",
|
||||
max_length=64,
|
||||
help_text="If your legal name is different to the name on your badge, "
|
||||
"fill this in, and we'll put it on your invoice. Otherwise, "
|
||||
"leave it blank.",
|
||||
blank=True,
|
||||
)
|
||||
of_legal_age = models.BooleanField(
|
||||
default=False,
|
||||
verbose_name="18+?",
|
||||
blank=True,
|
||||
)
|
||||
dietary_requirements = models.CharField(
|
||||
max_length=256,
|
||||
blank=True,
|
||||
)
|
||||
accessibility_requirements = models.CharField(
|
||||
max_length=256,
|
||||
blank=True,
|
||||
)
|
||||
gender = models.CharField(
|
||||
max_length=64,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
|
||||
# Inventory Models
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import symposion.speakers
|
||||
import sys
|
||||
|
||||
from registrasion import forms
|
||||
from registrasion import models as rego
|
||||
from registrasion.controllers import discount
|
||||
|
@ -7,6 +10,7 @@ from registrasion.controllers.product import ProductController
|
|||
|
||||
from collections import namedtuple
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib import messages
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
@ -30,6 +34,12 @@ GuidedRegistrationSection.__new__.__defaults__ = (
|
|||
(None,) * len(GuidedRegistrationSection._fields)
|
||||
)
|
||||
|
||||
def get_form(name):
|
||||
dot = name.rindex(".")
|
||||
mod_name, form_name = name[:dot], name[dot + 1:]
|
||||
__import__(mod_name)
|
||||
return getattr(sys.modules[mod_name], form_name)
|
||||
|
||||
@login_required
|
||||
def guided_registration(request, page_id=0):
|
||||
''' Goes through the registration process in order,
|
||||
|
@ -55,9 +65,12 @@ def guided_registration(request, page_id=0):
|
|||
)
|
||||
|
||||
# Step 1: Fill in a badge and collect a voucher code
|
||||
profile = rego.BadgeAndProfile.get_instance(attendee)
|
||||
try:
|
||||
profile = attendee.attendeeprofilebase
|
||||
except ObjectDoesNotExist:
|
||||
profile = None
|
||||
|
||||
if profile is None:
|
||||
if not profile:
|
||||
# TODO: if voucherform is invalid, make sure that profileform does not save
|
||||
voucher_form, voucher_handled = handle_voucher(request, "voucher")
|
||||
profile_form, profile_handled = handle_profile(request, "profile")
|
||||
|
@ -158,14 +171,29 @@ def handle_profile(request, prefix):
|
|||
attendee = rego.Attendee.get_instance(request.user)
|
||||
|
||||
try:
|
||||
profile = rego.BadgeAndProfile.objects.get(attendee=attendee)
|
||||
profile = attendee.attendeeprofilebase
|
||||
except ObjectDoesNotExist:
|
||||
profile = None
|
||||
|
||||
# TODO: pull down the speaker's real name from the Speaker profile
|
||||
ProfileForm = get_form(settings.ATTENDEE_PROFILE_FORM)
|
||||
|
||||
form = forms.ProfileForm(
|
||||
# Load a pre-entered name from the speaker's profile,
|
||||
# if they have one.
|
||||
try:
|
||||
speaker_profile = request.user.speaker_profile
|
||||
speaker_name = speaker_profile.name
|
||||
except ObjectDoesNotExist:
|
||||
speaker_name = None
|
||||
|
||||
|
||||
name_field = ProfileForm.Meta.model.name_field()
|
||||
initial = {}
|
||||
if name_field is not None:
|
||||
initial[name_field] = speaker_name
|
||||
|
||||
form = ProfileForm(
|
||||
request.POST or None,
|
||||
initial=initial,
|
||||
instance=profile,
|
||||
prefix=prefix
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue