diff --git a/registrasion/contrib/mail.py b/registrasion/contrib/mail.py index 06ca8fd2..e667c570 100644 --- a/registrasion/contrib/mail.py +++ b/registrasion/contrib/mail.py @@ -58,6 +58,12 @@ def __send_email__(template_prefix, to, kind, **kwargs): except AttributeError: bcc_email = None - email = EmailMultiAlternatives(subject, message_plaintext, from_email, to, bcc=bcc_email) + email = EmailMultiAlternatives( + subject, + message_plaintext, + from_email, + to, + bcc=bcc_email, + ) email.attach_alternative(message_html, "text/html") email.send() diff --git a/registrasion/controllers/cart.py b/registrasion/controllers/cart.py index d0a9f057..9f27ab49 100644 --- a/registrasion/controllers/cart.py +++ b/registrasion/controllers/cart.py @@ -1,5 +1,10 @@ +from .batch import BatchController +from .category import CategoryController +from .discount import DiscountController +from .flag import FlagController +from .product import ProductController + import collections -import contextlib import datetime import functools import itertools @@ -16,12 +21,6 @@ from registrasion.models import commerce from registrasion.models import conditions from registrasion.models import inventory -from.batch import BatchController -from .category import CategoryController -from .discount import DiscountController -from .flag import FlagController -from .product import ProductController - def _modifies_cart(func): ''' Decorator that makes the wrapped function raise ValidationError @@ -94,11 +93,10 @@ class CartController(object): self.cart.time_last_updated = timezone.now() self.cart.reservation_duration = max(reservations) - def end_batch(self): ''' Calls ``_end_batch`` if a modification has been performed in the previous batch. ''' - if hasattr(self,'_modified_by_batch'): + if hasattr(self, '_modified_by_batch'): self._end_batch() def _end_batch(self): diff --git a/registrasion/controllers/category.py b/registrasion/controllers/category.py index 4adf09b6..e1865404 100644 --- a/registrasion/controllers/category.py +++ b/registrasion/controllers/category.py @@ -9,6 +9,7 @@ from django.db.models import Value from .batch import BatchController + class AllProducts(object): pass diff --git a/registrasion/controllers/discount.py b/registrasion/controllers/discount.py index 984fe214..9329f7e6 100644 --- a/registrasion/controllers/discount.py +++ b/registrasion/controllers/discount.py @@ -12,6 +12,7 @@ from django.db.models import Sum from django.db.models import Value from django.db.models import When + class DiscountAndQuantity(object): ''' Represents a discount that can be applied to a product or category for a given user. diff --git a/registrasion/controllers/flag.py b/registrasion/controllers/flag.py index c094da59..b8d1b4e3 100644 --- a/registrasion/controllers/flag.py +++ b/registrasion/controllers/flag.py @@ -1,5 +1,4 @@ import itertools -import operator from collections import defaultdict from collections import namedtuple diff --git a/registrasion/forms.py b/registrasion/forms.py index 7e7ddc16..2b5ef97b 100644 --- a/registrasion/forms.py +++ b/registrasion/forms.py @@ -2,7 +2,6 @@ from registrasion.models import commerce from registrasion.models import inventory from django import forms -from django.core.exceptions import ValidationError class ApplyCreditNoteForm(forms.Form): @@ -54,10 +53,11 @@ def ProductsForm(category, products): type. ''' # Each Category.RENDER_TYPE value has a subclass here. + cat = inventory.Category RENDER_TYPES = { - inventory.Category.RENDER_TYPE_QUANTITY: _QuantityBoxProductsForm, - inventory.Category.RENDER_TYPE_RADIO: _RadioButtonProductsForm, - inventory.Category.RENDER_TYPE_ITEM_QUANTITY: _ItemQuantityProductsForm, + cat.RENDER_TYPE_QUANTITY: _QuantityBoxProductsForm, + cat.RENDER_TYPE_RADIO: _RadioButtonProductsForm, + cat.RENDER_TYPE_ITEM_QUANTITY: _ItemQuantityProductsForm, } # Produce a subclass of _ProductsForm which we can alter the base_fields on @@ -211,13 +211,15 @@ class _RadioButtonProductsForm(_ProductsForm): ) def add_product_error(self, product, error): - self.add_error(cls.FIELD, error) + self.add_error(self.FIELD, error) + class _ItemQuantityProductsForm(_ProductsForm): ''' Products entry form that allows users to select a product type, and enter a quantity of that product. This version _only_ allows a single - product type to be purchased. This form is usually used in concert with the - _ItemQuantityProductsFormSet to allow selection of multiple products.''' + product type to be purchased. This form is usually used in concert with + the _ItemQuantityProductsFormSet to allow selection of multiple + products.''' CHOICE_FIELD = "choice" QUANTITY_FIELD = "quantity" diff --git a/registrasion/tests/patches.py b/registrasion/tests/patches.py index 7d7cd66c..26c63789 100644 --- a/registrasion/tests/patches.py +++ b/registrasion/tests/patches.py @@ -2,6 +2,7 @@ from django.utils import timezone from registrasion.contrib import mail + class SetTimeMixin(object): ''' Patches timezone.now() for the duration of a test case. Allows us to test time-based conditions (ceilings etc) relatively easily. ''' diff --git a/registrasion/tests/test_batch.py b/registrasion/tests/test_batch.py index 70370799..aa11f113 100644 --- a/registrasion/tests/test_batch.py +++ b/registrasion/tests/test_batch.py @@ -1,16 +1,8 @@ -import datetime import pytz -from django.core.exceptions import ValidationError - -from controller_helpers import TestingCartController from test_cart import RegistrationCartTestCase from registrasion.controllers.batch import BatchController -from registrasion.controllers.discount import DiscountController -from registrasion.controllers.product import ProductController -from registrasion.models import commerce -from registrasion.models import conditions UTC = pytz.timezone('UTC') @@ -124,6 +116,7 @@ class BatchTestCase(RegistrationCartTestCase): def test_batch_end_functionality_is_called(self): class Ender(object): end_count = 0 + def end_batch(self): self.end_count += 1 diff --git a/registrasion/tests/test_cart.py b/registrasion/tests/test_cart.py index bee94322..a6803150 100644 --- a/registrasion/tests/test_cart.py +++ b/registrasion/tests/test_cart.py @@ -375,7 +375,7 @@ class BasicCartTests(RegistrationCartTestCase): with BatchController.batch(self.USER_1): # Memoise the cart - same_cart = TestingCartController.for_user(self.USER_1) + TestingCartController.for_user(self.USER_1) # Do nothing on exit rev_1 = self.reget(cart.cart).revision diff --git a/registrasion/urls.py b/registrasion/urls.py index d87b13fe..b6b120c1 100644 --- a/registrasion/urls.py +++ b/registrasion/urls.py @@ -1,4 +1,3 @@ -import views from reporting import views as reporting_views from django.conf.urls import include @@ -38,7 +37,11 @@ public = [ reports = [ url(r"^$", reporting_views.reports_list, name="reports_list"), - url(r"^credit_notes/?$", reporting_views.credit_notes, name="credit_notes"), + url( + r"^credit_notes/?$", + reporting_views.credit_notes, + name="credit_notes" + ), url( r"^product_status/?$", reporting_views.product_status, diff --git a/registrasion/views.py b/registrasion/views.py index 13ebd927..7216273e 100644 --- a/registrasion/views.py +++ b/registrasion/views.py @@ -355,7 +355,10 @@ def product_category(request, category_id): if not products: messages.warning( request, - "There are no products available from category: " + category.name, + ( + "There are no products available from category: " + + category.name + ), ) return redirect("dashboard") @@ -456,7 +459,7 @@ def _set_quantities_from_products_form(products_form, current_cart): id__in=pks, ).select_related("category").order_by("id") - quantities.sort(key = lambda i: i[0]) + quantities.sort(key=lambda i: i[0]) # Match the product objects to their quantities product_quantities = [