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
...
 
@@ -347,3 +347,18 @@ class VoucherForm(forms.Form):
 
        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
...
 
@@ -13,10 +13,12 @@ from .views import (
 
    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"),
registrasion/views.py
Show inline comments
...
 
@@ -18,6 +18,7 @@ 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
...
 
@@ -790,3 +791,30 @@ def credit_note(request, note_id, access_code=None):
 
    }
 

	
 
    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)