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.
This commit is contained in:
		
							parent
							
								
									c64d0eaab8
								
							
						
					
					
						commit
						897915f121
					
				
					 3 changed files with 45 additions and 0 deletions
				
			
		|  | @ -347,3 +347,18 @@ class VoucherForm(forms.Form): | ||||||
|         help_text="If you have a voucher code, enter it here", |         help_text="If you have a voucher code, enter it here", | ||||||
|         required=False, |         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) | ||||||
|  |  | ||||||
|  | @ -13,10 +13,12 @@ from .views import ( | ||||||
|     invoice_access, |     invoice_access, | ||||||
|     edit_profile, |     edit_profile, | ||||||
|     guided_registration, |     guided_registration, | ||||||
|  |     amend_registration, | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| public = [ | public = [ | ||||||
|  |     url(r"^amend/([0-9]+)$", amend_registration, name="amend_registration"), | ||||||
|     url(r"^category/([0-9]+)$", product_category, name="product_category"), |     url(r"^category/([0-9]+)$", product_category, name="product_category"), | ||||||
|     url(r"^checkout$", checkout, name="checkout"), |     url(r"^checkout$", checkout, name="checkout"), | ||||||
|     url(r"^credit_note/([0-9]+)$", credit_note, name="credit_note"), |     url(r"^credit_note/([0-9]+)$", credit_note, name="credit_note"), | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ from collections import namedtuple | ||||||
| from django.conf import settings | from django.conf import settings | ||||||
| from django.contrib.auth.decorators import login_required | from django.contrib.auth.decorators import login_required | ||||||
| from django.contrib.auth.decorators import user_passes_test | from django.contrib.auth.decorators import user_passes_test | ||||||
|  | from django.contrib.auth.models import User | ||||||
| from django.contrib import messages | from django.contrib import messages | ||||||
| from django.core.exceptions import ObjectDoesNotExist | from django.core.exceptions import ObjectDoesNotExist | ||||||
| from django.core.exceptions import ValidationError | 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) |     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) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Christopher Neugebauer
						Christopher Neugebauer