Changeset - 897915f1217d
[Not reviewed]
0 3 0
Christopher Neugebauer - 8 years ago 2016-09-03 04:22:32
chrisjrn@gmail.com
Adds the amend_registration view, which currently can display all of the products that the user has added to their current cart, and not much else.
3 files changed with 45 insertions and 0 deletions:
0 comments (0 inline, 0 general)
registrasion/forms.py
Show inline comments
...
 
@@ -338,12 +338,27 @@ class _ItemQuantityProductsFormSet(_HasProductsFields, forms.BaseFormSet):
 

	
 
    def add_product_error(self, product, error):
 
        for form in self.forms:
 
            form.add_product_error(product, error)
 

	
 

	
 
class VoucherForm(forms.Form):
 
    voucher = forms.CharField(
 
        label="Voucher code",
 
        help_text="If you have a voucher code, enter it here",
 
        required=False,
 
    )
 

	
 

	
 
class StaffProductsForm(forms.Form):
 
    ''' Form for allowing staff to add an item to a user's cart. '''
 

	
 
    product = forms.ModelChoiceField(
 
        widget=forms.Select,
 
        queryset=inventory.Product.objects.all(),
 
    )
 

	
 
    quantity = forms.IntegerField(
 
        min_value=0,
 
    )
 

	
 
StaffProductsFormSet = forms.formset_factory(StaffProductsForm)
registrasion/urls.py
Show inline comments
...
 
@@ -4,28 +4,30 @@ from django.conf.urls import include
 
from django.conf.urls import url
 

	
 
from .views import (
 
    product_category,
 
    checkout,
 
    credit_note,
 
    invoice,
 
    manual_payment,
 
    refund,
 
    invoice_access,
 
    edit_profile,
 
    guided_registration,
 
    amend_registration,
 
)
 

	
 

	
 
public = [
 
    url(r"^amend/([0-9]+)$", amend_registration, name="amend_registration"),
 
    url(r"^category/([0-9]+)$", product_category, name="product_category"),
 
    url(r"^checkout$", checkout, name="checkout"),
 
    url(r"^credit_note/([0-9]+)$", credit_note, name="credit_note"),
 
    url(r"^invoice/([0-9]+)$", invoice, name="invoice"),
 
    url(r"^invoice/([0-9]+)/([A-Z0-9]+)$", invoice, name="invoice"),
 
    url(r"^invoice/([0-9]+)/manual_payment$",
 
        manual_payment, name="manual_payment"),
 
    url(r"^invoice/([0-9]+)/refund$",
 
        refund, name="refund"),
 
    url(r"^invoice_access/([A-Z0-9]+)$", invoice_access,
 
        name="invoice_access"),
 
    url(r"^profile$", edit_profile, name="attendee_edit"),
registrasion/views.py
Show inline comments
...
 
@@ -9,24 +9,25 @@ from registrasion.controllers.batch import BatchController
 
from registrasion.controllers.cart import CartController
 
from registrasion.controllers.credit_note import CreditNoteController
 
from registrasion.controllers.discount import DiscountController
 
from registrasion.controllers.invoice import InvoiceController
 
from registrasion.controllers.product import ProductController
 
from registrasion.exceptions import CartValidationError
 

	
 
from collections import namedtuple
 

	
 
from django.conf import settings
 
from django.contrib.auth.decorators import login_required
 
from django.contrib.auth.decorators import user_passes_test
 
from django.contrib.auth.models import User
 
from django.contrib import messages
 
from django.core.exceptions import ObjectDoesNotExist
 
from django.core.exceptions import ValidationError
 
from django.http import Http404
 
from django.shortcuts import redirect
 
from django.shortcuts import render
 

	
 

	
 
_GuidedRegistrationSection = namedtuple(
 
    "GuidedRegistrationSection",
 
    (
 
        "title",
...
 
@@ -781,12 +782,39 @@ def credit_note(request, note_id, access_code=None):
 
        )
 
        refund_form = forms.ManualCreditNoteRefundForm(
 
            prefix="refund_note",
 
        )
 

	
 
    data = {
 
        "credit_note": current_note.credit_note,
 
        "apply_form": apply_form,
 
        "refund_form": refund_form,
 
    }
 

	
 
    return render(request, "registrasion/credit_note.html", data)
 

	
 

	
 
@user_passes_test(_staff_only)
 
def amend_registration(request, user_id):
 
    ''' Allows staff to amend a user's current registration cart, and etc etc.
 
    '''
 

	
 
    user = User.objects.get(id=int(user_id))
 
    current_cart = CartController.for_user(user)
 

	
 
    items = commerce.ProductItem.objects.filter(
 
        cart=current_cart.cart,
 
    ).select_related("product")
 

	
 
    initial = [{"product": i.product, "quantity": i.quantity} for i in items]
 

	
 
    form = forms.StaffProductsFormSet(
 
        request.POST or None,
 
        initial=initial,
 
        prefix="products",
 
    )
 

	
 
    data = {
 
        "form": form,
 
    }
 

	
 
    return render(request, "registrasion/amend_registration.html", data)
0 comments (0 inline, 0 general)