flake8 fixes

This commit is contained in:
Christopher Neugebauer 2016-04-07 13:26:25 +10:00
parent 2b59151429
commit 8e95bb7469
12 changed files with 14 additions and 19 deletions

View file

@ -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:

View file

@ -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:

View file

@ -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,

View file

@ -1,4 +1,5 @@
from django.core.exceptions import ValidationError
class CartValidationError(ValidationError):
pass

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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. '''