Adds ATTENDEE_PROFILE_MODEL as a thing that needs to be specified in settings.py.

Fixes #65
This commit is contained in:
Christopher Neugebauer 2016-09-20 11:10:48 +10:00
parent e2d027f71b
commit 6e4d2fab16
3 changed files with 18 additions and 6 deletions

View file

@ -46,9 +46,13 @@ Because every conference is different, Registrasion lets you define your own att
.. autoclass :: AttendeeProfileBase
:members: name_field, invoice_recipient
Once you've subclassed ``AttendeeProfileBase``, you'll need to implement a form that lets attendees fill out their profile.
You specify how to find that model in your Django ``settings.py`` file::
You specify how to find that form in your Django ``settings.py`` file::
ATTENDEE_PROFILE_MODEL = "democon.models.AttendeeProfile"
When Registrasion asks the to edit their profile, a default form will be generated, showing all of the fields on the profile model.
If you want to customise the profile editing form, you need to specify the location of that form in your ``settings.py`` file as well.
ATTENDEE_PROFILE_FORM = "democon.forms.AttendeeProfileForm"

View file

@ -274,7 +274,6 @@ def discount_status(request, form):
discounts = form.cleaned_data["discount"]
items = commerce.DiscountItem.objects.filter(
Q(discount__in=discounts),
).select_related("cart", "product", "product__category")

View file

@ -16,6 +16,7 @@ from registrasion.exceptions import CartValidationError
from collections import namedtuple
from django import forms as django_forms
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import user_passes_test
@ -59,7 +60,7 @@ class GuidedRegistrationSection(_GuidedRegistrationSection):
pass
def get_form(name):
def get_object(name):
dot = name.rindex(".")
mod_name, form_name = name[:dot], name[dot + 1:]
__import__(mod_name)
@ -274,6 +275,16 @@ def edit_profile(request):
return render(request, "registrasion/profile_form.html", data)
# Define the attendee profile form, or get a default.
try:
ProfileForm = get_object(settings.ATTENDEE_PROFILE_FORM)
except:
class ProfileForm(django_forms.ModelForm):
class Meta:
model = get_object(settings.ATTENDEE_PROFILE_MODEL)
exclude = ["attendee"]
def _handle_profile(request, prefix):
''' Returns a profile form instance, and a boolean which is true if the
form was handled. '''
@ -287,8 +298,6 @@ def _handle_profile(request, prefix):
except ObjectDoesNotExist:
profile = None
ProfileForm = get_form(settings.ATTENDEE_PROFILE_FORM)
# Load a pre-entered name from the speaker's profile,
# if they have one.
try: