Changeset - b320b227aae9
[Not reviewed]
Merge
0 3 1
Christopher Neugebauer - 8 years ago 2016-04-08 09:44:55
chrisjrn@gmail.com
Merge branch 'guided_registration_3'
4 files changed with 76 insertions and 18 deletions:
0 comments (0 inline, 0 general)
registrasion/migrations/0017_auto_20160408_0731.py
Show inline comments
 
new file 100644
 
# -*- 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'),
 
        ),
 
    ]
registrasion/models.py
Show inline comments
...
 
@@ -51,3 +51,3 @@ class Attendee(models.Model):
 
    completed_registration = models.BooleanField(default=False)
 
    highest_complete_category = models.IntegerField(default=0)
 
    guided_categories_complete = models.ManyToManyField("category")
 

	
registrasion/templatetags/registrasion_tags.py
Show inline comments
...
 
@@ -32,3 +32,9 @@ def items_pending(context):
 
        cart__active=True,
 
    ).select_related("product", "product__category")
 
    ).select_related(
 
        "product",
 
        "product__category",
 
    ).order_by(
 
        "product__category__order",
 
        "product__order",
 
    )
 
    return all_items
registrasion/views.py
Show inline comments
...
 
@@ -54,2 +54,5 @@ def guided_registration(request, page_id=0):
 

	
 
    SESSION_KEY = "guided_registration_categories"
 
    ASK_FOR_PROFILE = 777  # Magic number. Meh.
 

	
 
    next_step = redirect("guided_registration")
...
 
@@ -73,5 +76,15 @@ def guided_registration(request, page_id=0):
 

	
 
    if not profile:
 
        # TODO: if voucherform is invalid, make sure
 
        # that profileform does not save
 
    # Figure out if we need to show the profile form and the voucher form
 
    show_profile_and_voucher = False
 
    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")
...
 
@@ -96,3 +109,3 @@ def guided_registration(request, page_id=0):
 

	
 
        last_category = attendee.highest_complete_category
 
        starting = attendee.guided_categories_complete.count() == 0
 

	
...
 
@@ -100,11 +113,15 @@ def guided_registration(request, page_id=0):
 
        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:
 
            # We've filled in every category
 
            attendee.completed_registration = True
 
            attendee.save()
 
            return next_step
 
        cats = cats.order_by("order")
 

	
 
        request.session[SESSION_KEY] = []
 

	
 
        if last_category == 0:
 
        if starting:
 
            # Only display the first Category
...
 
@@ -127,2 +144,8 @@ def guided_registration(request, page_id=0):
 

	
 
        if len(available_products) == 0:
 
            # We've filled in every category
 
            attendee.completed_registration = True
 
            attendee.save()
 
            return next_step
 

	
 
        for category in cats:
...
 
@@ -143,10 +166,13 @@ def guided_registration(request, page_id=0):
 
            )
 

	
 
            if products:
 
                # This product category does not exist for this user
 
                # This product category has items to show.
 
                sections.append(section)
 
                # 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:
 
                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 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)
 

	
...
 
@@ -158,2 +184,4 @@ def guided_registration(request, page_id=0):
 
            attendee.save()
 
            if SESSION_KEY in request.session:
 
                del request.session[SESSION_KEY]
 
            # We've successfully processed everything
0 comments (0 inline, 0 general)