Fix flake8 warnings

This commit is contained in:
Christopher Neugebauer 2016-03-25 14:51:39 +11:00
parent 4069d4bb32
commit 8d66ed5715
6 changed files with 22 additions and 14 deletions

View file

@ -43,7 +43,6 @@ def CategoryForm(category):
if not prod.can_add_with_enabling_conditions(user, 0): if not prod.can_add_with_enabling_conditions(user, 0):
self.disable_product(product) self.disable_product(product)
products = rego.Product.objects.filter(category=category).order_by("order") products = rego.Product.objects.filter(category=category).order_by("order")
for product in products: for product in products:

View file

@ -4,6 +4,7 @@ from django import template
register = template.Library() register = template.Library()
@register.assignment_tag(takes_context=True) @register.assignment_tag(takes_context=True)
def available_categories(context): def available_categories(context):
''' Returns all of the available product categories ''' ''' Returns all of the available product categories '''

View file

@ -208,7 +208,7 @@ class DiscountTestCase(RegistrationCartTestCase):
# in the same way # in the same way
for user in (self.USER_1, self.USER_2): for user in (self.USER_1, self.USER_2):
cart = CartController.for_user(user) cart = CartController.for_user(user)
cart.add_to_cart(self.PROD_1, 1) # Enable the discount cart.add_to_cart(self.PROD_1, 1) # Enable the discount
cart.add_to_cart(self.PROD_3, 1) cart.add_to_cart(self.PROD_3, 1)
discount_items = list(cart.cart.discountitem_set.all()) discount_items = list(cart.cart.discountitem_set.all())

View file

@ -95,13 +95,13 @@ class VoucherTestCases(RegistrationCartTestCase):
self.assertEqual(1, len(current_cart.cart.discountitem_set.all())) self.assertEqual(1, len(current_cart.cart.discountitem_set.all()))
def test_voucher_codes_unique(self): def test_voucher_codes_unique(self):
voucher1 = self.new_voucher(code="VOUCHER") self.new_voucher(code="VOUCHER")
with self.assertRaises(IntegrityError): with self.assertRaises(IntegrityError):
voucher2 = self.new_voucher(code="VOUCHER") self.new_voucher(code="VOUCHER")
def test_multiple_vouchers_work(self): def test_multiple_vouchers_work(self):
voucher1 = self.new_voucher(code="VOUCHER1") self.new_voucher(code="VOUCHER1")
voucher2 = self.new_voucher(code="VOUCHER2") self.new_voucher(code="VOUCHER2")
def test_vouchers_case_insensitive(self): def test_vouchers_case_insensitive(self):
voucher = self.new_voucher(code="VOUCHeR") voucher = self.new_voucher(code="VOUCHeR")

View file

@ -8,5 +8,6 @@ urlpatterns = patterns(
url(r"^invoice/([0-9]+)/pay$", "pay_invoice", name="pay_invoice"), url(r"^invoice/([0-9]+)/pay$", "pay_invoice", name="pay_invoice"),
url(r"^profile$", "edit_profile", name="profile"), url(r"^profile$", "edit_profile", name="profile"),
url(r"^register$", "guided_registration", name="guided_registration"), url(r"^register$", "guided_registration", name="guided_registration"),
url(r"^register/([0-9]+)$", "guided_registration", name="guided_registration"), url(r"^register/([0-9]+)$", "guided_registration",
name="guided_registration"),
) )

View file

@ -2,7 +2,6 @@ from registrasion import forms
from registrasion import models as rego from registrasion import models as rego
from registrasion.controllers.cart import CartController from registrasion.controllers.cart import CartController
from registrasion.controllers.invoice import InvoiceController from registrasion.controllers.invoice import InvoiceController
from registrasion.controllers.product import ProductController
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
@ -83,6 +82,7 @@ def edit_profile(request):
} }
return render(request, "profile_form.html", data) return render(request, "profile_form.html", data)
@login_required @login_required
def product_category(request, category_id): def product_category(request, category_id):
''' Registration selections form for a specific category of items. ''' Registration selections form for a specific category of items.
@ -103,11 +103,17 @@ def product_category(request, category_id):
products = products.order_by("order") products = products.order_by("order")
if request.method == "POST": if request.method == "POST":
cat_form = CategoryForm(request.POST, request.FILES, prefix=PRODUCTS_FORM_PREFIX) cat_form = CategoryForm(
request.POST,
request.FILES,
prefix=PRODUCTS_FORM_PREFIX)
cat_form.disable_products_for_user(request.user) cat_form.disable_products_for_user(request.user)
voucher_form = forms.VoucherForm(request.POST, prefix=VOUCHERS_FORM_PREFIX) voucher_form = forms.VoucherForm(
request.POST,
prefix=VOUCHERS_FORM_PREFIX)
if voucher_form.is_valid() and voucher_form.cleaned_data["voucher"].strip(): if (voucher_form.is_valid() and
voucher_form.cleaned_data["voucher"].strip()):
# Apply voucher # Apply voucher
# leave # leave
voucher = voucher_form.cleaned_data["voucher"] voucher = voucher_form.cleaned_data["voucher"]
@ -119,7 +125,7 @@ def product_category(request, category_id):
elif cat_form.is_valid(): elif cat_form.is_valid():
try: try:
handle_valid_cat_form(cat_form, current_cart) handle_valid_cat_form(cat_form, current_cart)
except ValidationError as ve: except ValidationError:
pass pass
# If category is required, the user must have at least one # If category is required, the user must have at least one
@ -153,7 +159,6 @@ def product_category(request, category_id):
quantities = [] quantities = []
for product in products: for product in products:
# Only add items that are enabled. # Only add items that are enabled.
prod = ProductController(product)
try: try:
quantity = items.get(product=product).quantity quantity = items.get(product=product).quantity
except ObjectDoesNotExist: except ObjectDoesNotExist:
@ -166,7 +171,6 @@ def product_category(request, category_id):
voucher_form = forms.VoucherForm(prefix=VOUCHERS_FORM_PREFIX) voucher_form = forms.VoucherForm(prefix=VOUCHERS_FORM_PREFIX)
data = { data = {
"category": category, "category": category,
"form": cat_form, "form": cat_form,
@ -175,6 +179,7 @@ def product_category(request, category_id):
return render(request, "product_category.html", data) return render(request, "product_category.html", data)
@transaction.atomic @transaction.atomic
def handle_valid_cat_form(cat_form, current_cart): def handle_valid_cat_form(cat_form, current_cart):
for product_id, quantity, field_name in cat_form.product_quantities(): for product_id, quantity, field_name in cat_form.product_quantities():
@ -187,6 +192,7 @@ def handle_valid_cat_form(cat_form, current_cart):
raise ValidationError("Cannot add that stuff") raise ValidationError("Cannot add that stuff")
current_cart.end_batch() current_cart.end_batch()
@login_required @login_required
def checkout(request): def checkout(request):
''' Runs checkout for the current cart of items, ideally generating an ''' Runs checkout for the current cart of items, ideally generating an
@ -212,6 +218,7 @@ def invoice(request, invoice_id):
return render(request, "invoice.html", data) return render(request, "invoice.html", data)
@login_required @login_required
def pay_invoice(request, invoice_id): def pay_invoice(request, invoice_id):
''' Marks the invoice with the given invoice id as paid. ''' Marks the invoice with the given invoice id as paid.