Second pass at guided registration, including profile page
This commit is contained in:
parent
05923a9a8f
commit
dcad2d5f7c
2 changed files with 48 additions and 22 deletions
|
@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import F, Q
|
from django.db.models import F, Q
|
||||||
|
@ -46,6 +47,15 @@ class BadgeAndProfile(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Badge for: %s of %s" % (self.name, self.company)
|
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
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -18,25 +18,45 @@ def guided_registration(request, page_id=0):
|
||||||
making sure user sees all valid categories.
|
making sure user sees all valid categories.
|
||||||
|
|
||||||
WORK IN PROGRESS: the finalised version of this view will allow
|
WORK IN PROGRESS: the finalised version of this view will allow
|
||||||
grouping of categories into a specific page. Currently, page_id simply
|
grouping of categories into a specific page. Currently, it just goes
|
||||||
refers to the category_id. Future versions will have pages containing
|
through each category one by one
|
||||||
categories.
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
page_id = int(page_id)
|
dashboard = redirect("dashboard")
|
||||||
if page_id != 0:
|
next_step = redirect("guided_registration")
|
||||||
ret = product_category_inner(request, page_id)
|
|
||||||
if ret is not True:
|
# Step 1: Fill in a badge
|
||||||
|
attendee = rego.Attendee.get_instance(request.user)
|
||||||
|
profile = rego.BadgeAndProfile.get_instance(attendee)
|
||||||
|
|
||||||
|
if profile is None:
|
||||||
|
ret = edit_profile(request)
|
||||||
|
profile_new = rego.BadgeAndProfile.get_instance(attendee)
|
||||||
|
if profile_new is None:
|
||||||
|
# No new profile was created
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
# Go to next page in the guided registration
|
|
||||||
cats = rego.Category.objects
|
|
||||||
cats = cats.filter(id__gt=page_id).order_by("order")
|
|
||||||
|
|
||||||
if len(cats) > 0:
|
|
||||||
return redirect("guided_registration", cats[0].id)
|
|
||||||
else:
|
else:
|
||||||
return redirect("dashboard")
|
return next_step
|
||||||
|
|
||||||
|
# Step 2: Go through each of the categories in order
|
||||||
|
category = attendee.highest_complete_category
|
||||||
|
|
||||||
|
# Get the next category
|
||||||
|
cats = rego.Category.objects
|
||||||
|
cats = cats.filter(id__gt=category).order_by("order")
|
||||||
|
|
||||||
|
if len(cats) == 0:
|
||||||
|
# We've filled in every category
|
||||||
|
return dashboard
|
||||||
|
|
||||||
|
ret = product_category(request, cats[0].id)
|
||||||
|
attendee_new = rego.Attendee.get_instance(request.user)
|
||||||
|
if attendee_new.highest_complete_category == category:
|
||||||
|
# We've not yet completed this category
|
||||||
|
return ret
|
||||||
|
else:
|
||||||
|
return next_step
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def edit_profile(request):
|
def edit_profile(request):
|
||||||
|
@ -60,16 +80,7 @@ def edit_profile(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def product_category(request, category_id):
|
def product_category(request, category_id):
|
||||||
ret = product_category_inner(request, category_id)
|
|
||||||
if ret is not True:
|
|
||||||
return ret
|
|
||||||
else:
|
|
||||||
return redirect("dashboard")
|
|
||||||
|
|
||||||
def product_category_inner(request, category_id):
|
|
||||||
''' Registration selections form for a specific category of items.
|
''' Registration selections form for a specific category of items.
|
||||||
It returns a rendered template if this page needs to display stuff,
|
|
||||||
otherwise it returns True.
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
PRODUCTS_FORM_PREFIX = "products"
|
PRODUCTS_FORM_PREFIX = "products"
|
||||||
|
@ -81,6 +92,8 @@ def product_category_inner(request, category_id):
|
||||||
|
|
||||||
CategoryForm = forms.CategoryForm(category)
|
CategoryForm = forms.CategoryForm(category)
|
||||||
|
|
||||||
|
attendee = rego.Attendee.get_instance(request.user)
|
||||||
|
|
||||||
products = rego.Product.objects.filter(category=category)
|
products = rego.Product.objects.filter(category=category)
|
||||||
products = products.order_by("order")
|
products = products.order_by("order")
|
||||||
|
|
||||||
|
@ -101,7 +114,10 @@ def product_category_inner(request, category_id):
|
||||||
elif cat_form.is_valid():
|
elif cat_form.is_valid():
|
||||||
try:
|
try:
|
||||||
handle_valid_cat_form(cat_form, current_cart)
|
handle_valid_cat_form(cat_form, current_cart)
|
||||||
return True
|
if category_id > attendee.highest_complete_category:
|
||||||
|
attendee.highest_complete_category = category_id
|
||||||
|
attendee.save()
|
||||||
|
return redirect("dashboard")
|
||||||
except ValidationError as ve:
|
except ValidationError as ve:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue