Merge branch 'guided_registration_3'

This commit is contained in:
Christopher Neugebauer 2016-04-08 19:44:55 +10:00
commit b320b227aa
4 changed files with 78 additions and 20 deletions

View file

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-04-08 07:31
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('registrasion', '0016_auto_20160408_0234'),
]
operations = [
migrations.RemoveField(
model_name='attendee',
name='highest_complete_category',
),
migrations.AddField(
model_name='attendee',
name='guided_categories_complete',
field=models.ManyToManyField(to='registrasion.Category'),
),
]

View file

@ -49,7 +49,7 @@ class Attendee(models.Model):
db_index=True, db_index=True,
) )
completed_registration = models.BooleanField(default=False) completed_registration = models.BooleanField(default=False)
highest_complete_category = models.IntegerField(default=0) guided_categories_complete = models.ManyToManyField("category")
class AttendeeProfileBase(models.Model): class AttendeeProfileBase(models.Model):

View file

@ -30,7 +30,13 @@ def items_pending(context):
all_items = rego.ProductItem.objects.filter( all_items = rego.ProductItem.objects.filter(
cart__user=context.request.user, cart__user=context.request.user,
cart__active=True, cart__active=True,
).select_related("product", "product__category") ).select_related(
"product",
"product__category",
).order_by(
"product__category__order",
"product__order",
)
return all_items return all_items

View file

@ -52,6 +52,9 @@ def guided_registration(request, page_id=0):
through each category one by one through each category one by one
''' '''
SESSION_KEY = "guided_registration_categories"
ASK_FOR_PROFILE = 777 # Magic number. Meh.
next_step = redirect("guided_registration") next_step = redirect("guided_registration")
sections = [] sections = []
@ -71,9 +74,19 @@ def guided_registration(request, page_id=0):
except ObjectDoesNotExist: except ObjectDoesNotExist:
profile = None profile = None
if not profile: # Figure out if we need to show the profile form and the voucher form
# TODO: if voucherform is invalid, make sure show_profile_and_voucher = False
# that profileform does not save if SESSION_KEY not in request.session:
if not profile:
show_profile_and_voucher = True
else:
if request.session[SESSION_KEY] == ASK_FOR_PROFILE:
show_profile_and_voucher = True
if show_profile_and_voucher:
# Keep asking for the profile until everything passes.
request.session[SESSION_KEY] = ASK_FOR_PROFILE
voucher_form, voucher_handled = handle_voucher(request, "voucher") voucher_form, voucher_handled = handle_voucher(request, "voucher")
profile_form, profile_handled = handle_profile(request, "profile") profile_form, profile_handled = handle_profile(request, "profile")
@ -94,19 +107,23 @@ def guided_registration(request, page_id=0):
else: else:
# We're selling products # We're selling products
last_category = attendee.highest_complete_category starting = attendee.guided_categories_complete.count() == 0
# Get the next category # Get the next category
cats = rego.Category.objects cats = rego.Category.objects
cats = cats.filter(id__gt=last_category).order_by("order") if SESSION_KEY in request.session:
_cats = request.session[SESSION_KEY]
cats = cats.filter(id__in=_cats)
else:
cats = cats.exclude(
id__in=attendee.guided_categories_complete.all(),
)
if cats.count() == 0: cats = cats.order_by("order")
# We've filled in every category
attendee.completed_registration = True
attendee.save()
return next_step
if last_category == 0: request.session[SESSION_KEY] = []
if starting:
# Only display the first Category # Only display the first Category
title = "Select ticket type" title = "Select ticket type"
current_step = 2 current_step = 2
@ -125,6 +142,12 @@ def guided_registration(request, page_id=0):
products=all_products, products=all_products,
)) ))
if len(available_products) == 0:
# We've filled in every category
attendee.completed_registration = True
attendee.save()
return next_step
for category in cats: for category in cats:
products = [ products = [
i for i in available_products i for i in available_products
@ -141,14 +164,17 @@ def guided_registration(request, page_id=0):
discounts=discounts, discounts=discounts,
form=products_form, form=products_form,
) )
if products:
# This product category does not exist for this user
sections.append(section)
if request.method == "POST" and not products_form.errors: if products:
if category.id > attendee.highest_complete_category: # This product category has items to show.
# This is only saved if we pass each form with no errors. sections.append(section)
attendee.highest_complete_category = category.id # Add this to the list of things to show if the form errors.
request.session[SESSION_KEY].append(category.id)
if request.method == "POST" and not products_form.errors:
# This is only saved if we pass each form with no errors,
# and if the form actually has products.
attendee.guided_categories_complete.add(category)
if sections and request.method == "POST": if sections and request.method == "POST":
for section in sections: for section in sections:
@ -156,6 +182,8 @@ def guided_registration(request, page_id=0):
break break
else: else:
attendee.save() attendee.save()
if SESSION_KEY in request.session:
del request.session[SESSION_KEY]
# We've successfully processed everything # We've successfully processed everything
return next_step return next_step