From 660e8cb75f6753f0bf2b0062a05d5e67c06ae298 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 1 Apr 2016 16:58:55 +1100 Subject: [PATCH 1/3] Removes BadgeAndProfile.get_instance --- registrasion/models.py | 9 --------- registrasion/views.py | 9 ++++++--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/registrasion/models.py b/registrasion/models.py index d9ddfc1e..92babf1b 100644 --- a/registrasion/models.py +++ b/registrasion/models.py @@ -48,15 +48,6 @@ class BadgeAndProfile(models.Model): 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 diff --git a/registrasion/views.py b/registrasion/views.py index 230227c7..1539c846 100644 --- a/registrasion/views.py +++ b/registrasion/views.py @@ -55,9 +55,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.badgeandprofile + 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,7 +161,7 @@ def handle_profile(request, prefix): attendee = rego.Attendee.get_instance(request.user) try: - profile = rego.BadgeAndProfile.objects.get(attendee=attendee) + profile = attendee.badgeandprofile except ObjectDoesNotExist: profile = None From be277c17d22d7827b4b3aee743552f594e765886 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 1 Apr 2016 21:21:09 +1100 Subject: [PATCH 2/3] =?UTF-8?q?BadgeAndProfile=20is=20replaced=20with=20At?= =?UTF-8?q?tendeeProfileBase=20=E2=80=94=20consumer=20apps=20should=20subc?= =?UTF-8?q?lass=20AttendeeProfileBase=20to=20make=20the=20registration=20p?= =?UTF-8?q?rocess=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 From 89cba55807c19026563297d48803c3021d0bb2f2 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 1 Apr 2016 21:39:54 +1100 Subject: [PATCH 3/3] Pre-fills the attendee name from a speaker profile, if there is one. Resolves #8. --- registrasion/models.py | 6 ++++++ registrasion/views.py | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/registrasion/models.py b/registrasion/models.py index 1e7d04c2..80e0141c 100644 --- a/registrasion/models.py +++ b/registrasion/models.py @@ -47,6 +47,12 @@ class AttendeeProfileBase(models.Model): registration progess. ''' + @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) diff --git a/registrasion/views.py b/registrasion/views.py index 9c109ae9..edd619ff 100644 --- a/registrasion/views.py +++ b/registrasion/views.py @@ -1,3 +1,4 @@ +import symposion.speakers import sys from registrasion import forms @@ -174,12 +175,25 @@ def handle_profile(request, prefix): except ObjectDoesNotExist: profile = None - # TODO: pull down the speaker's real name from the Speaker profile - ProfileForm = get_form(settings.ATTENDEE_PROFILE_FORM) + # 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 )