flake8 fixes
This commit is contained in:
		
							parent
							
								
									2b59151429
								
							
						
					
					
						commit
						8e95bb7469
					
				
					 12 changed files with 14 additions and 19 deletions
				
			
		|  | @ -199,7 +199,8 @@ class CartController(object): | ||||||
|         carts_with_voucher = active_carts.filter(vouchers=voucher) |         carts_with_voucher = active_carts.filter(vouchers=voucher) | ||||||
|         carts_with_voucher = carts_with_voucher.exclude(pk=self.cart.id) |         carts_with_voucher = carts_with_voucher.exclude(pk=self.cart.id) | ||||||
|         if carts_with_voucher.count() >= voucher.limit: |         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 |         # It's not valid for users to re-enter a voucher they already have | ||||||
|         user_carts_with_voucher = carts_with_voucher.filter( |         user_carts_with_voucher = carts_with_voucher.filter( | ||||||
|  | @ -275,12 +276,11 @@ class CartController(object): | ||||||
|         codes that are no longer available. ''' |         codes that are no longer available. ''' | ||||||
| 
 | 
 | ||||||
|         # Fix vouchers first (this affects available discounts) |         # Fix vouchers first (this affects available discounts) | ||||||
|         active_carts = rego.Cart.reserved_carts() |  | ||||||
|         to_remove = [] |         to_remove = [] | ||||||
|         for voucher in self.cart.vouchers.all(): |         for voucher in self.cart.vouchers.all(): | ||||||
|             try: |             try: | ||||||
|                 self._test_voucher(voucher) |                 self._test_voucher(voucher) | ||||||
|             except ValidationError as ve: |             except ValidationError: | ||||||
|                 to_remove.append(voucher) |                 to_remove.append(voucher) | ||||||
| 
 | 
 | ||||||
|         for voucher in to_remove: |         for voucher in to_remove: | ||||||
|  |  | ||||||
|  | @ -45,7 +45,6 @@ class ConditionController(object): | ||||||
|         except KeyError: |         except KeyError: | ||||||
|             return ConditionController() |             return ConditionController() | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     SINGLE = True |     SINGLE = True | ||||||
|     PLURAL = False |     PLURAL = False | ||||||
|     NONE = True |     NONE = True | ||||||
|  | @ -155,7 +154,6 @@ class ConditionController(object): | ||||||
|                 if not met and product not in messages: |                 if not met and product not in messages: | ||||||
|                     messages[product] = message |                     messages[product] = message | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         valid = defaultdict(lambda: True) |         valid = defaultdict(lambda: True) | ||||||
|         for product in itertools.chain(mandatory, non_mandatory): |         for product in itertools.chain(mandatory, non_mandatory): | ||||||
|             if product in mandatory: |             if product in mandatory: | ||||||
|  |  | ||||||
|  | @ -59,7 +59,6 @@ def available_discounts(user, categories, products): | ||||||
|     accepted_discounts = set() |     accepted_discounts = set() | ||||||
|     failed_discounts = set() |     failed_discounts = set() | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     for discount in potential_discounts: |     for discount in potential_discounts: | ||||||
|         real_discount = rego.DiscountBase.objects.get_subclass( |         real_discount = rego.DiscountBase.objects.get_subclass( | ||||||
|             pk=discount.discount.pk, |             pk=discount.discount.pk, | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| from django.core.exceptions import ValidationError | from django.core.exceptions import ValidationError | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| class CartValidationError(ValidationError): | class CartValidationError(ValidationError): | ||||||
|     pass |     pass | ||||||
|  |  | ||||||
|  | @ -48,7 +48,10 @@ class _QuantityBoxProductsForm(_ProductsForm): | ||||||
|     def set_fields(cls, category, products): |     def set_fields(cls, category, products): | ||||||
|         for product in products: |         for product in products: | ||||||
|             if product.description: |             if product.description: | ||||||
|                 help_text = "$%d each -- %s" % (product.price, product.description) |                 help_text = "$%d each -- %s" % ( | ||||||
|  |                     product.price, | ||||||
|  |                     product.description, | ||||||
|  |                 ) | ||||||
|             else: |             else: | ||||||
|                 help_text = "$%d each" % product.price |                 help_text = "$%d each" % product.price | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -142,7 +142,6 @@ class BasicCartTests(RegistrationCartTestCase): | ||||||
|     def test_get_cart(self): |     def test_get_cart(self): | ||||||
|         current_cart = TestingCartController.for_user(self.USER_1) |         current_cart = TestingCartController.for_user(self.USER_1) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         current_cart.next_cart() |         current_cart.next_cart() | ||||||
| 
 | 
 | ||||||
|         old_cart = current_cart |         old_cart = current_cart | ||||||
|  | @ -214,7 +213,6 @@ class BasicCartTests(RegistrationCartTestCase): | ||||||
|         with self.assertRaises(ValidationError): |         with self.assertRaises(ValidationError): | ||||||
|             current_cart.add_to_cart(self.PROD_1, 10) |             current_cart.add_to_cart(self.PROD_1, 10) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         current_cart.next_cart() |         current_cart.next_cart() | ||||||
| 
 | 
 | ||||||
|         current_cart = TestingCartController.for_user(self.USER_1) |         current_cart = TestingCartController.for_user(self.USER_1) | ||||||
|  | @ -272,7 +270,6 @@ class BasicCartTests(RegistrationCartTestCase): | ||||||
|         with self.assertRaises(ValidationError): |         with self.assertRaises(ValidationError): | ||||||
|             current_cart.add_to_cart(self.PROD_3, 1) |             current_cart.add_to_cart(self.PROD_3, 1) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         current_cart.next_cart() |         current_cart.next_cart() | ||||||
| 
 | 
 | ||||||
|         current_cart = TestingCartController.for_user(self.USER_1) |         current_cart = TestingCartController.for_user(self.USER_1) | ||||||
|  | @ -325,7 +322,6 @@ class BasicCartTests(RegistrationCartTestCase): | ||||||
|         current_cart.add_to_cart(item, quantity) |         current_cart.add_to_cart(item, quantity) | ||||||
|         self.assertTrue(item in prods) |         self.assertTrue(item in prods) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         current_cart.next_cart() |         current_cart.next_cart() | ||||||
| 
 | 
 | ||||||
|         current_cart = TestingCartController.for_user(self.USER_1) |         current_cart = TestingCartController.for_user(self.USER_1) | ||||||
|  |  | ||||||
|  | @ -140,7 +140,6 @@ class CeilingsTestCases(RegistrationCartTestCase): | ||||||
|         first_cart = TestingCartController.for_user(self.USER_1) |         first_cart = TestingCartController.for_user(self.USER_1) | ||||||
|         first_cart.add_to_cart(self.PROD_1, 1) |         first_cart.add_to_cart(self.PROD_1, 1) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         first_cart.next_cart() |         first_cart.next_cart() | ||||||
| 
 | 
 | ||||||
|         second_cart = TestingCartController.for_user(self.USER_2) |         second_cart = TestingCartController.for_user(self.USER_2) | ||||||
|  | @ -176,7 +175,6 @@ class CeilingsTestCases(RegistrationCartTestCase): | ||||||
|         cart.add_to_cart(self.PROD_1, 1) |         cart.add_to_cart(self.PROD_1, 1) | ||||||
|         self.assertEqual(1, len(cart.cart.discountitem_set.all())) |         self.assertEqual(1, len(cart.cart.discountitem_set.all())) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         cart.next_cart() |         cart.next_cart() | ||||||
| 
 | 
 | ||||||
|         # The second cart has no voucher attached, so should apply the |         # The second cart has no voucher attached, so should apply the | ||||||
|  |  | ||||||
|  | @ -5,7 +5,6 @@ from decimal import Decimal | ||||||
| from registrasion import models as rego | from registrasion import models as rego | ||||||
| from registrasion.controllers import discount | from registrasion.controllers import discount | ||||||
| from cart_controller_helper import TestingCartController | from cart_controller_helper import TestingCartController | ||||||
| from registrasion.controllers.invoice import InvoiceController |  | ||||||
| 
 | 
 | ||||||
| from test_cart import RegistrationCartTestCase | from test_cart import RegistrationCartTestCase | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -241,7 +241,6 @@ class EnablingConditionTestCases(RegistrationCartTestCase): | ||||||
|         cart = TestingCartController.for_user(self.USER_1) |         cart = TestingCartController.for_user(self.USER_1) | ||||||
|         cart.add_to_cart(self.PROD_3, 1) |         cart.add_to_cart(self.PROD_3, 1) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         cart.next_cart() |         cart.next_cart() | ||||||
| 
 | 
 | ||||||
|         cart_2 = TestingCartController.for_user(self.USER_1) |         cart_2 = TestingCartController.for_user(self.USER_1) | ||||||
|  | @ -260,7 +259,6 @@ class EnablingConditionTestCases(RegistrationCartTestCase): | ||||||
|         cart = TestingCartController.for_user(self.USER_1) |         cart = TestingCartController.for_user(self.USER_1) | ||||||
|         cart.add_to_cart(self.PROD_2, 1) |         cart.add_to_cart(self.PROD_2, 1) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         cart.next_cart() |         cart.next_cart() | ||||||
| 
 | 
 | ||||||
|         cart_2 = TestingCartController.for_user(self.USER_1) |         cart_2 = TestingCartController.for_user(self.USER_1) | ||||||
|  |  | ||||||
|  | @ -197,4 +197,4 @@ class InvoiceTestCase(RegistrationCartTestCase): | ||||||
|     def test_cannot_generate_blank_invoice(self): |     def test_cannot_generate_blank_invoice(self): | ||||||
|         current_cart = TestingCartController.for_user(self.USER_1) |         current_cart = TestingCartController.for_user(self.USER_1) | ||||||
|         with self.assertRaises(ValidationError): |         with self.assertRaises(ValidationError): | ||||||
|             invoice_1 = InvoiceController.for_cart(current_cart.cart) |             InvoiceController.for_cart(current_cart.cart) | ||||||
|  |  | ||||||
|  | @ -125,7 +125,6 @@ class VoucherTestCases(RegistrationCartTestCase): | ||||||
|         current_cart = TestingCartController.for_user(self.USER_1) |         current_cart = TestingCartController.for_user(self.USER_1) | ||||||
|         current_cart.apply_voucher(voucher.code) |         current_cart.apply_voucher(voucher.code) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         current_cart.next_cart() |         current_cart.next_cart() | ||||||
| 
 | 
 | ||||||
|         current_cart = TestingCartController.for_user(self.USER_1) |         current_cart = TestingCartController.for_user(self.USER_1) | ||||||
|  |  | ||||||
|  | @ -336,7 +336,9 @@ def set_quantities_from_products_form(products_form, current_cart): | ||||||
|     quantities = list(products_form.product_quantities()) |     quantities = list(products_form.product_quantities()) | ||||||
| 
 | 
 | ||||||
|     pks = [i[0] for i in 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 = [ |     product_quantities = [ | ||||||
|         (products.get(pk=i[0]), i[1]) for i in 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) |     return redirect("invoice", current_invoice.invoice.id) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def checkout_errors(request, errors): | def checkout_errors(request, errors): | ||||||
| 
 | 
 | ||||||
|     error_list = [] |     error_list = [] | ||||||
|  | @ -419,6 +422,7 @@ def checkout_errors(request, errors): | ||||||
| 
 | 
 | ||||||
|     return render(request, "registrasion/checkout_errors.html", data) |     return render(request, "registrasion/checkout_errors.html", data) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| @login_required | @login_required | ||||||
| def invoice(request, invoice_id): | def invoice(request, invoice_id): | ||||||
|     ''' Displays an invoice for a given invoice id. ''' |     ''' Displays an invoice for a given invoice id. ''' | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Christopher Neugebauer
						Christopher Neugebauer