diff --git a/registrasion/controllers/cart.py b/registrasion/controllers/cart.py index abf56357..2b711c70 100644 --- a/registrasion/controllers/cart.py +++ b/registrasion/controllers/cart.py @@ -199,7 +199,8 @@ class CartController(object): carts_with_voucher = active_carts.filter(vouchers=voucher) carts_with_voucher = carts_with_voucher.exclude(pk=self.cart.id) if carts_with_voucher.count() >= voucher.limit: - raise ValidationError("Voucher %s is no longer available" % voucher.code) + raise ValidationError( + "Voucher %s is no longer available" % voucher.code) # It's not valid for users to re-enter a voucher they already have user_carts_with_voucher = carts_with_voucher.filter( @@ -275,12 +276,11 @@ class CartController(object): codes that are no longer available. ''' # Fix vouchers first (this affects available discounts) - active_carts = rego.Cart.reserved_carts() to_remove = [] for voucher in self.cart.vouchers.all(): try: self._test_voucher(voucher) - except ValidationError as ve: + except ValidationError: to_remove.append(voucher) for voucher in to_remove: diff --git a/registrasion/controllers/conditions.py b/registrasion/controllers/conditions.py index 6e5fb82f..03b50118 100644 --- a/registrasion/controllers/conditions.py +++ b/registrasion/controllers/conditions.py @@ -45,7 +45,6 @@ class ConditionController(object): except KeyError: return ConditionController() - SINGLE = True PLURAL = False NONE = True @@ -155,7 +154,6 @@ class ConditionController(object): if not met and product not in messages: messages[product] = message - valid = defaultdict(lambda: True) for product in itertools.chain(mandatory, non_mandatory): if product in mandatory: diff --git a/registrasion/controllers/discount.py b/registrasion/controllers/discount.py index f03063a8..624e78a1 100644 --- a/registrasion/controllers/discount.py +++ b/registrasion/controllers/discount.py @@ -59,7 +59,6 @@ def available_discounts(user, categories, products): accepted_discounts = set() failed_discounts = set() - for discount in potential_discounts: real_discount = rego.DiscountBase.objects.get_subclass( pk=discount.discount.pk, diff --git a/registrasion/exceptions.py b/registrasion/exceptions.py index ac6624d9..6444a462 100644 --- a/registrasion/exceptions.py +++ b/registrasion/exceptions.py @@ -1,4 +1,5 @@ from django.core.exceptions import ValidationError + class CartValidationError(ValidationError): pass diff --git a/registrasion/forms.py b/registrasion/forms.py index b7259782..47dacd3d 100644 --- a/registrasion/forms.py +++ b/registrasion/forms.py @@ -48,7 +48,10 @@ class _QuantityBoxProductsForm(_ProductsForm): def set_fields(cls, category, products): for product in products: if product.description: - help_text = "$%d each -- %s" % (product.price, product.description) + help_text = "$%d each -- %s" % ( + product.price, + product.description, + ) else: help_text = "$%d each" % product.price diff --git a/registrasion/tests/test_cart.py b/registrasion/tests/test_cart.py index df5e290f..d47d659e 100644 --- a/registrasion/tests/test_cart.py +++ b/registrasion/tests/test_cart.py @@ -142,7 +142,6 @@ class BasicCartTests(RegistrationCartTestCase): def test_get_cart(self): current_cart = TestingCartController.for_user(self.USER_1) - current_cart.next_cart() old_cart = current_cart @@ -214,7 +213,6 @@ class BasicCartTests(RegistrationCartTestCase): with self.assertRaises(ValidationError): current_cart.add_to_cart(self.PROD_1, 10) - current_cart.next_cart() current_cart = TestingCartController.for_user(self.USER_1) @@ -272,7 +270,6 @@ class BasicCartTests(RegistrationCartTestCase): with self.assertRaises(ValidationError): current_cart.add_to_cart(self.PROD_3, 1) - current_cart.next_cart() current_cart = TestingCartController.for_user(self.USER_1) @@ -325,7 +322,6 @@ class BasicCartTests(RegistrationCartTestCase): current_cart.add_to_cart(item, quantity) self.assertTrue(item in prods) - current_cart.next_cart() current_cart = TestingCartController.for_user(self.USER_1) diff --git a/registrasion/tests/test_ceilings.py b/registrasion/tests/test_ceilings.py index cc333c29..f8481fea 100644 --- a/registrasion/tests/test_ceilings.py +++ b/registrasion/tests/test_ceilings.py @@ -140,7 +140,6 @@ class CeilingsTestCases(RegistrationCartTestCase): first_cart = TestingCartController.for_user(self.USER_1) first_cart.add_to_cart(self.PROD_1, 1) - first_cart.next_cart() second_cart = TestingCartController.for_user(self.USER_2) @@ -176,7 +175,6 @@ class CeilingsTestCases(RegistrationCartTestCase): cart.add_to_cart(self.PROD_1, 1) self.assertEqual(1, len(cart.cart.discountitem_set.all())) - cart.next_cart() # The second cart has no voucher attached, so should apply the diff --git a/registrasion/tests/test_discount.py b/registrasion/tests/test_discount.py index c4211c0f..fb35330e 100644 --- a/registrasion/tests/test_discount.py +++ b/registrasion/tests/test_discount.py @@ -5,7 +5,6 @@ from decimal import Decimal from registrasion import models as rego from registrasion.controllers import discount from cart_controller_helper import TestingCartController -from registrasion.controllers.invoice import InvoiceController from test_cart import RegistrationCartTestCase diff --git a/registrasion/tests/test_enabling_condition.py b/registrasion/tests/test_enabling_condition.py index bedb6c86..5d0e410c 100644 --- a/registrasion/tests/test_enabling_condition.py +++ b/registrasion/tests/test_enabling_condition.py @@ -241,7 +241,6 @@ class EnablingConditionTestCases(RegistrationCartTestCase): cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_3, 1) - cart.next_cart() cart_2 = TestingCartController.for_user(self.USER_1) @@ -260,7 +259,6 @@ class EnablingConditionTestCases(RegistrationCartTestCase): cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_2, 1) - cart.next_cart() cart_2 = TestingCartController.for_user(self.USER_1) diff --git a/registrasion/tests/test_invoice.py b/registrasion/tests/test_invoice.py index 5dc1559b..19332392 100644 --- a/registrasion/tests/test_invoice.py +++ b/registrasion/tests/test_invoice.py @@ -197,4 +197,4 @@ class InvoiceTestCase(RegistrationCartTestCase): def test_cannot_generate_blank_invoice(self): current_cart = TestingCartController.for_user(self.USER_1) with self.assertRaises(ValidationError): - invoice_1 = InvoiceController.for_cart(current_cart.cart) + InvoiceController.for_cart(current_cart.cart) diff --git a/registrasion/tests/test_voucher.py b/registrasion/tests/test_voucher.py index a8686fb1..a8bc6b00 100644 --- a/registrasion/tests/test_voucher.py +++ b/registrasion/tests/test_voucher.py @@ -125,7 +125,6 @@ class VoucherTestCases(RegistrationCartTestCase): current_cart = TestingCartController.for_user(self.USER_1) current_cart.apply_voucher(voucher.code) - current_cart.next_cart() current_cart = TestingCartController.for_user(self.USER_1) diff --git a/registrasion/views.py b/registrasion/views.py index 231783a3..b3f9212d 100644 --- a/registrasion/views.py +++ b/registrasion/views.py @@ -336,7 +336,9 @@ def set_quantities_from_products_form(products_form, current_cart): quantities = list(products_form.product_quantities()) pks = [i[0] for i in quantities] - products = rego.Product.objects.filter(id__in=pks).select_related("category") + products = rego.Product.objects.filter( + id__in=pks, + ).select_related("category") product_quantities = [ (products.get(pk=i[0]), i[1]) for i in quantities @@ -405,6 +407,7 @@ def checkout(request): return redirect("invoice", current_invoice.invoice.id) + def checkout_errors(request, errors): error_list = [] @@ -419,6 +422,7 @@ def checkout_errors(request, errors): return render(request, "registrasion/checkout_errors.html", data) + @login_required def invoice(request, invoice_id): ''' Displays an invoice for a given invoice id. '''