From be277c17d22d7827b4b3aee743552f594e765886 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 1 Apr 2016 21:21:09 +1100 Subject: [PATCH] =?UTF-8?q?BadgeAndProfile=20is=20replaced=20with=20Attend?= =?UTF-8?q?eeProfileBase=20=E2=80=94=20consumer=20apps=20should=20subclass?= =?UTF-8?q?=20AttendeeProfileBase=20to=20make=20the=20registration=20proce?= =?UTF-8?q?ss=20work=20:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- registrasion/forms.py | 8 --- .../migrations/0011_auto_20160401_0943.py | 30 ++++++++ registrasion/models.py | 69 ++----------------- registrasion/views.py | 17 ++++- 4 files changed, 49 insertions(+), 75 deletions(-) create mode 100644 registrasion/migrations/0011_auto_20160401_0943.py diff --git a/registrasion/forms.py b/registrasion/forms.py index eb6f2949..f1527aa5 100644 --- a/registrasion/forms.py +++ b/registrasion/forms.py @@ -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", diff --git a/registrasion/migrations/0011_auto_20160401_0943.py b/registrasion/migrations/0011_auto_20160401_0943.py new file mode 100644 index 00000000..a8b2deac --- /dev/null +++ b/registrasion/migrations/0011_auto_20160401_0943.py @@ -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', + ), + ] diff --git a/registrasion/models.py b/registrasion/models.py index 92babf1b..1e7d04c2 100644 --- a/registrasion/models.py +++ b/registrasion/models.py @@ -41,73 +41,14 @@ 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 ''' - - def __str__(self): - return "Badge for: %s of %s" % (self.name, self.company) - - def save(self): - if not self.name_per_invoice: - self.name_per_invoice = self.name - super(BadgeAndProfile, self).save() +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. + ''' 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 diff --git a/registrasion/views.py b/registrasion/views.py index 1539c846..9c109ae9 100644 --- a/registrasion/views.py +++ b/registrasion/views.py @@ -1,3 +1,5 @@ +import sys + from registrasion import forms from registrasion import models as rego from registrasion.controllers import discount @@ -7,6 +9,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 +33,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, @@ -56,7 +65,7 @@ def guided_registration(request, page_id=0): # Step 1: Fill in a badge and collect a voucher code try: - profile = attendee.badgeandprofile + profile = attendee.attendeeprofilebase except ObjectDoesNotExist: profile = None @@ -161,13 +170,15 @@ def handle_profile(request, prefix): attendee = rego.Attendee.get_instance(request.user) try: - profile = attendee.badgeandprofile + profile = attendee.attendeeprofilebase except ObjectDoesNotExist: profile = None # TODO: pull down the speaker's real name from the Speaker profile - form = forms.ProfileForm( + ProfileForm = get_form(settings.ATTENDEE_PROFILE_FORM) + + form = ProfileForm( request.POST or None, instance=profile, prefix=prefix