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
...
 
@@ -344,6 +344,21 @@ class _ItemQuantityProductsFormSet(_HasProductsFields, forms.BaseFormSet):
 
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
...
 
@@ -10,16 +10,18 @@ from .views import (
 
    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$",
registrasion/views.py
Show inline comments
...
 
@@ -15,12 +15,13 @@ 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
...
 
@@ -787,6 +788,33 @@ def credit_note(request, note_id, access_code=None):
 
        "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)