Merge branch 'guided_registration_2'
This commit is contained in:
commit
28fbacbd28
3 changed files with 141 additions and 40 deletions
|
@ -57,6 +57,11 @@ class BadgeAndProfile(models.Model):
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
if not self.name_per_invoice:
|
||||||
|
self.name_per_invoice = self.name
|
||||||
|
super(BadgeAndProfile, self).save()
|
||||||
|
|
||||||
attendee = models.OneToOneField(Attendee, on_delete=models.CASCADE)
|
attendee = models.OneToOneField(Attendee, on_delete=models.CASCADE)
|
||||||
|
|
||||||
# Things that appear on badge
|
# Things that appear on badge
|
||||||
|
|
|
@ -49,3 +49,8 @@ def items_purchased(context):
|
||||||
quantity = pp.aggregate(Sum("quantity"))["quantity__sum"]
|
quantity = pp.aggregate(Sum("quantity"))["quantity__sum"]
|
||||||
out.append(ProductAndQuantity(product, quantity))
|
out.append(ProductAndQuantity(product, quantity))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def multiply(value, arg):
|
||||||
|
''' Multiplies value by arg '''
|
||||||
|
return value * arg
|
||||||
|
|
|
@ -5,14 +5,31 @@ from registrasion.controllers.cart import CartController
|
||||||
from registrasion.controllers.invoice import InvoiceController
|
from registrasion.controllers.invoice import InvoiceController
|
||||||
from registrasion.controllers.product import ProductController
|
from registrasion.controllers.product import ProductController
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib import messages
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
from django.http import Http404
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
|
||||||
|
GuidedRegistrationSection = namedtuple(
|
||||||
|
"GuidedRegistrationSection",
|
||||||
|
(
|
||||||
|
"title",
|
||||||
|
"discounts",
|
||||||
|
"description",
|
||||||
|
"form",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
GuidedRegistrationSection.__new__.__defaults__ = (
|
||||||
|
(None,) * len(GuidedRegistrationSection._fields)
|
||||||
|
)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def guided_registration(request, page_id=0):
|
def guided_registration(request, page_id=0):
|
||||||
''' Goes through the registration process in order,
|
''' Goes through the registration process in order,
|
||||||
|
@ -26,46 +43,118 @@ def guided_registration(request, page_id=0):
|
||||||
dashboard = redirect("dashboard")
|
dashboard = redirect("dashboard")
|
||||||
next_step = redirect("guided_registration")
|
next_step = redirect("guided_registration")
|
||||||
|
|
||||||
attendee = rego.Attendee.get_instance(request.user)
|
sections = []
|
||||||
if attendee.completed_registration:
|
|
||||||
return dashboard
|
|
||||||
|
|
||||||
# Step 1: Fill in a badge
|
attendee = rego.Attendee.get_instance(request.user)
|
||||||
|
|
||||||
|
if attendee.completed_registration:
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
"registrasion/guided_registration_complete.html",
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
|
||||||
|
# Step 1: Fill in a badge and collect a voucher code
|
||||||
profile = rego.BadgeAndProfile.get_instance(attendee)
|
profile = rego.BadgeAndProfile.get_instance(attendee)
|
||||||
|
|
||||||
if profile is None:
|
if profile is None:
|
||||||
ret = edit_profile(request)
|
# TODO: if voucherform is invalid, make sure that profileform does not save
|
||||||
profile_new = rego.BadgeAndProfile.get_instance(attendee)
|
voucher_form, voucher_handled = handle_voucher(request, "voucher")
|
||||||
if profile_new is None:
|
profile_form, profile_handled = handle_profile(request, "profile")
|
||||||
# No new profile was created
|
|
||||||
return ret
|
voucher_section = GuidedRegistrationSection(
|
||||||
else:
|
title="Voucher Code",
|
||||||
|
form=voucher_form,
|
||||||
|
)
|
||||||
|
|
||||||
|
profile_section = GuidedRegistrationSection(
|
||||||
|
title="Profile and Personal Information",
|
||||||
|
form=profile_form,
|
||||||
|
)
|
||||||
|
|
||||||
|
title = "Attendee information"
|
||||||
|
current_step = 1
|
||||||
|
sections.append(voucher_section)
|
||||||
|
sections.append(profile_section)
|
||||||
|
else:
|
||||||
|
# We're selling products
|
||||||
|
|
||||||
|
last_category = attendee.highest_complete_category
|
||||||
|
|
||||||
|
# Get the next category
|
||||||
|
cats = rego.Category.objects
|
||||||
|
cats = cats.filter(id__gt=last_category).order_by("order")
|
||||||
|
|
||||||
|
if cats.count() == 0:
|
||||||
|
# We've filled in every category
|
||||||
|
attendee.completed_registration = True
|
||||||
|
attendee.save()
|
||||||
return next_step
|
return next_step
|
||||||
|
|
||||||
# Step 2: Go through each of the categories in order
|
if last_category == 0:
|
||||||
category = attendee.highest_complete_category
|
# Only display the first Category
|
||||||
|
title = "Select ticket type"
|
||||||
|
current_step = 2
|
||||||
|
cats = [cats[0]]
|
||||||
|
else:
|
||||||
|
# Set title appropriately for remaining categories
|
||||||
|
current_step = 3
|
||||||
|
title = "Additional items"
|
||||||
|
|
||||||
# Get the next category
|
for category in cats:
|
||||||
cats = rego.Category.objects
|
products = ProductController.available_products(
|
||||||
cats = cats.filter(id__gt=category).order_by("order")
|
request.user,
|
||||||
|
category=category,
|
||||||
|
)
|
||||||
|
|
||||||
if len(cats) == 0:
|
prefix = "category_" + str(category.id)
|
||||||
# We've filled in every category
|
p = handle_products(request, category, products, prefix)
|
||||||
attendee.completed_registration = True
|
products_form, discounts, products_handled = p
|
||||||
attendee.save()
|
|
||||||
return dashboard
|
|
||||||
|
|
||||||
ret = product_category(request, cats[0].id)
|
section = GuidedRegistrationSection(
|
||||||
attendee_new = rego.Attendee.get_instance(request.user)
|
title=category.name,
|
||||||
if attendee_new.highest_complete_category == category:
|
description=category.description,
|
||||||
# We've not yet completed this category
|
discounts=discounts,
|
||||||
return ret
|
form=products_form,
|
||||||
else:
|
)
|
||||||
return next_step
|
sections.append(section)
|
||||||
|
|
||||||
|
if request.method == "POST" and not products_form.errors:
|
||||||
|
if category.id > attendee.highest_complete_category:
|
||||||
|
# This is only saved if we pass each form with no errors.
|
||||||
|
attendee.highest_complete_category = category.id
|
||||||
|
|
||||||
|
|
||||||
|
if sections and request.method == "POST":
|
||||||
|
for section in sections:
|
||||||
|
if section.form.errors:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
attendee.save()
|
||||||
|
# We've successfully processed everything
|
||||||
|
return next_step
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"current_step": current_step,
|
||||||
|
"sections": sections,
|
||||||
|
"title" : title,
|
||||||
|
"total_steps": 3,
|
||||||
|
}
|
||||||
|
return render(request, "registrasion/guided_registration.html", data)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def edit_profile(request):
|
def edit_profile(request):
|
||||||
|
form, handled = handle_profile(request, "profile")
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"form": form,
|
||||||
|
}
|
||||||
|
return render(request, "registrasion/profile_form.html", data)
|
||||||
|
|
||||||
|
def handle_profile(request, prefix):
|
||||||
|
''' Returns a profile form instance, and a boolean which is true if the
|
||||||
|
form was handled. '''
|
||||||
attendee = rego.Attendee.get_instance(request.user)
|
attendee = rego.Attendee.get_instance(request.user)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -73,17 +162,21 @@ def edit_profile(request):
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
profile = None
|
profile = None
|
||||||
|
|
||||||
form = forms.ProfileForm(request.POST or None, instance=profile)
|
# TODO: pull down the speaker's real name from the Speaker profile
|
||||||
|
|
||||||
|
form = forms.ProfileForm(
|
||||||
|
request.POST or None,
|
||||||
|
instance=profile,
|
||||||
|
prefix=prefix
|
||||||
|
)
|
||||||
|
|
||||||
|
handled = True if request.POST else False
|
||||||
|
|
||||||
if request.POST and form.is_valid():
|
if request.POST and form.is_valid():
|
||||||
form.instance.attendee = attendee
|
form.instance.attendee = attendee
|
||||||
form.save()
|
form.save()
|
||||||
|
|
||||||
data = {
|
return form, handled
|
||||||
"form": form,
|
|
||||||
}
|
|
||||||
return render(request, "registrasion/profile_form.html", data)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def product_category(request, category_id):
|
def product_category(request, category_id):
|
||||||
|
@ -112,11 +205,6 @@ def product_category(request, category_id):
|
||||||
if request.POST and not voucher_handled and not products_form.errors:
|
if request.POST and not voucher_handled and not products_form.errors:
|
||||||
# Only return to the dashboard if we didn't add a voucher code
|
# Only return to the dashboard if we didn't add a voucher code
|
||||||
# and if there's no errors in the products form
|
# and if there's no errors in the products form
|
||||||
|
|
||||||
attendee = rego.Attendee.get_instance(request.user)
|
|
||||||
if category_id > attendee.highest_complete_category:
|
|
||||||
attendee.highest_complete_category = category_id
|
|
||||||
attendee.save()
|
|
||||||
return redirect("dashboard")
|
return redirect("dashboard")
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
@ -248,6 +336,10 @@ def invoice(request, invoice_id):
|
||||||
|
|
||||||
invoice_id = int(invoice_id)
|
invoice_id = int(invoice_id)
|
||||||
inv = rego.Invoice.objects.get(pk=invoice_id)
|
inv = rego.Invoice.objects.get(pk=invoice_id)
|
||||||
|
|
||||||
|
if request.user != inv.cart.user and not request.user.is_staff:
|
||||||
|
raise Http404()
|
||||||
|
|
||||||
current_invoice = InvoiceController(inv)
|
current_invoice = InvoiceController(inv)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
@ -263,11 +355,10 @@ def pay_invoice(request, invoice_id):
|
||||||
WORK IN PROGRESS FUNCTION. Must be replaced with real payment workflow.
|
WORK IN PROGRESS FUNCTION. Must be replaced with real payment workflow.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
invoice_id = int(invoice_id)
|
invoice_id = int(invoice_id)
|
||||||
inv = rego.Invoice.objects.get(pk=invoice_id)
|
inv = rego.Invoice.objects.get(pk=invoice_id)
|
||||||
current_invoice = InvoiceController(inv)
|
current_invoice = InvoiceController(inv)
|
||||||
if not inv.paid and current_invoice.is_valid():
|
if not current_invoice.invoice.paid and not current_invoice.invoice.void:
|
||||||
current_invoice.pay("Demo invoice payment", inv.value)
|
current_invoice.pay("Demo invoice payment", inv.value)
|
||||||
|
|
||||||
return redirect("invoice", current_invoice.invoice.id)
|
return redirect("invoice", current_invoice.invoice.id)
|
||||||
|
|
Loading…
Reference in a new issue