Changeset - b5cbc3e39e27
[Not reviewed]
0 1 0
Christopher Neugebauer - 8 years ago 2016-09-14 05:00:53
chrisjrn@gmail.com
Renames guided_registration_complete to review
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
registrasion/views.py
Show inline comments
...
 
@@ -143,193 +143,193 @@ def guided_registration(request):
 

	
 
        # Get the next category
 
        cats = inventory.Category.objects
 
        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(),
 
            )
 

	
 
        cats = cats.order_by("order")
 

	
 
        request.session[SESSION_KEY] = []
 

	
 
        if starting:
 
            # 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"
 

	
 
        all_products = inventory.Product.objects.filter(
 
            category__in=cats,
 
        ).select_related("category")
 

	
 
        with BatchController.batch(request.user):
 
            available_products = set(ProductController.available_products(
 
                request.user,
 
                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:
 
                products = [
 
                    i for i in available_products
 
                    if i.category == category
 
                ]
 

	
 
                prefix = "category_" + str(category.id)
 
                p = _handle_products(request, category, products, prefix)
 
                products_form, discounts, products_handled = p
 

	
 
                section = GuidedRegistrationSection(
 
                    title=category.name,
 
                    description=category.description,
 
                    discounts=discounts,
 
                    form=products_form,
 
                )
 

	
 
                if products:
 
                    # 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:
 
                        # 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":
 
        for section in sections:
 
            if section.form.errors:
 
                break
 
        else:
 
            attendee.save()
 
            if SESSION_KEY in request.session:
 
                del request.session[SESSION_KEY]
 
            # 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
 
def review(request):
 
    ''' View for the review page. '''
 

	
 
    return render(
 
        request,
 
        "registrasion/guided_registration_complete.html",
 
        "registrasion/review.html",
 
        {},
 
    )
 

	
 

	
 
@login_required
 
def edit_profile(request):
 
    ''' View for editing an attendee's profile
 

	
 
    The user must be logged in to edit their profile.
 

	
 
    Returns:
 
        redirect or render:
 
            In the case of a ``POST`` request, it'll redirect to ``dashboard``,
 
            or otherwise, it will render ``registrasion/profile_form.html``
 
            with data::
 

	
 
                {
 
                    "form": form,  # Instance of ATTENDEE_PROFILE_FORM.
 
                }
 

	
 
    '''
 

	
 
    form, handled = _handle_profile(request, "profile")
 

	
 
    if handled and not form.errors:
 
        messages.success(
 
            request,
 
            "Your attendee profile was updated.",
 
        )
 
        return redirect("dashboard")
 

	
 
    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 = people.Attendee.get_instance(request.user)
 

	
 
    try:
 
        profile = attendee.attendeeprofilebase
 
        profile = people.AttendeeProfileBase.objects.get_subclass(
 
            pk=profile.id,
 
        )
 
    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:
 
        speaker_profile = request.user.speaker_profile
 
        speaker_name = speaker_profile.name
 
    except ObjectDoesNotExist:
 
        speaker_name = None
 

	
 
    name_field = ProfileForm.Meta.model.name_field()
 
    initial = {}
 
    if profile is None and name_field is not None:
 
        initial[name_field] = speaker_name
 

	
 
    form = ProfileForm(
 
        request.POST or None,
 
        initial=initial,
 
        instance=profile,
 
        prefix=prefix
 
    )
 

	
 
    handled = True if request.POST else False
 

	
 
    if request.POST and form.is_valid():
 
        form.instance.attendee = attendee
 
        form.save()
 

	
 
    return form, handled
 

	
 

	
 
@login_required
 
def product_category(request, category_id):
 
    ''' Form for selecting products from an individual product category.
 

	
 
    Arguments:
 
        category_id (castable to int): The id of the category to display.
 

	
 
    Returns:
 
        redirect or render:
 
            If the form has been sucessfully submitted, redirect to
 
            ``dashboard``. Otherwise, render
 
            ``registrasion/product_category.html`` with data::
 

	
 
                {
 
                    "category": category,         # An inventory.Category for
0 comments (0 inline, 0 general)