Adds voucher form to registration amendment

This commit is contained in:
Christopher Neugebauer 2016-09-03 15:53:54 +10:00
parent b9ee438b89
commit 5703221fba

View file

@ -826,8 +826,12 @@ def amend_registration(request, user_id):
prefix="products", prefix="products",
) )
voucher_form = forms.VoucherForm(
request.POST or None,
prefix="voucher",
)
if request.POST and formset.is_valid(): if request.POST and formset.is_valid():
print formset._errors
pq = [ pq = [
(f.cleaned_data["product"], f.cleaned_data["quantity"]) (f.cleaned_data["product"], f.cleaned_data["quantity"])
@ -846,12 +850,20 @@ def amend_registration(request, user_id):
if form.cleaned_data["product"] == product: if form.cleaned_data["product"] == product:
form.add_error("quantity", message) form.add_error("quantity", message)
if request.POST and voucher_form.is_valid():
try:
current_cart.apply_voucher(voucher_form.cleaned_data["voucher"])
return redirect(amend_registration, user_id)
except ValidationError as ve:
voucher_form.add_error(None, ve)
ic = ItemController(user) ic = ItemController(user)
data = { data = {
"user": user, "user": user,
"paid": ic.items_purchased(), "paid": ic.items_purchased(),
"cancelled": ic.items_released(), "cancelled": ic.items_released(),
"form": formset, "form": formset,
"voucher_form": voucher_form,
} }
return render(request, "registrasion/amend_registration.html", data) return render(request, "registrasion/amend_registration.html", data)