Changeset - 162db2481781
[Not reviewed]
0 9 0
Christopher Neugebauer - 8 years ago 2016-04-29 01:08:45
chrisjrn@gmail.com
Flake8 fixes
9 files changed with 86 insertions and 35 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/cart.py
Show inline comments
...
 
@@ -2,3 +2,2 @@ import collections
 
import datetime
 
import discount
 
import functools
...
 
@@ -380,3 +379,7 @@ class CartController(object):
 
        products = [i.product for i in product_items]
 
        discounts = DiscountController.available_discounts(self.cart.user, [], products)
 
        discounts = DiscountController.available_discounts(
 
            self.cart.user,
 
            [],
 
            products,
 
        )
 

	
registrasion/controllers/conditions.py
Show inline comments
 
import itertools
 
import operator
 

	
 
from collections import defaultdict
 
from collections import namedtuple
 

	
 
from django.db.models import Case
 
from django.db.models import Count
 
from django.db.models import F, Q
...
 
@@ -236,5 +231,5 @@ class TimeOrStockLimitFlagController(
 
        # Calculate category lines
 
        cat_items = F('categories__product__productitem__product__category')
 
        item_cats = F('categories__product__productitem__product__category')
 
        reserved_category_products = (
 
            Q(categories=F('categories__product__productitem__product__category')) &
 
            Q(categories=item_cats) &
 
            Q(categories__product__productitem__cart__in=reserved_carts)
registrasion/controllers/discount.py
Show inline comments
...
 
@@ -48,5 +48,5 @@ class DiscountController(object):
 
    def available_discounts(cls, user, categories, products):
 
        ''' Returns all discounts available to this user for the given categories
 
        and products. The discounts also list the available quantity for this user,
 
        not including products that are pending purchase. '''
 
        ''' Returns all discounts available to this user for the given
 
        categories and products. The discounts also list the available quantity
 
        for this user, not including products that are pending purchase. '''
 

	
...
 
@@ -57,3 +57,4 @@ class DiscountController(object):
 

	
 
        # Markers so that we don't need to evaluate given conditions more than once
 
        # Markers so that we don't need to evaluate given conditions
 
        # more than once
 
        accepted_discounts = set()
...
 
@@ -73,3 +74,4 @@ class DiscountController(object):
 
                # This clause is still available
 
                if discount in accepted_discounts or cond.is_met(user, filtered=True):
 
                is_accepted = discount in accepted_discounts
 
                if is_accepted or cond.is_met(user, filtered=True):
 
                    # This clause is valid for this user
...
 
@@ -91,3 +93,4 @@ class DiscountController(object):
 
        Returns:
 
            Sequence[discountbase]: All discounts that passed the filter function.
 
            Sequence[discountbase]: All discounts that passed the filter
 
            function.
 

	
...
 
@@ -96,3 +99,5 @@ class DiscountController(object):
 
        types = list(ConditionController._controllers())
 
        discounttypes = [i for i in types if issubclass(i, conditions.DiscountBase)]
 
        discounttypes = [
 
            i for i in types if issubclass(i, conditions.DiscountBase)
 
        ]
 

	
...
 
@@ -107,3 +112,4 @@ class DiscountController(object):
 
        # discounts that match categories for provided products
 
        product_category_discounts = conditions.DiscountForCategory.objects.filter(
 
        product_category_discounts = conditions.DiscountForCategory.objects
 
        product_category_discounts = product_category_discounts.filter(
 
            category__in=(product.category for product in products)
...
 
@@ -117,3 +123,5 @@ class DiscountController(object):
 

	
 
        all_category_discounts = category_discounts | product_category_discounts
 
        all_category_discounts = (
 
            category_discounts | product_category_discounts
 
        )
 
        all_category_discounts = all_category_discounts.select_related(
...
 
@@ -138,3 +146,4 @@ class DiscountController(object):
 

	
 
        # Map from discount key to itself (contains annotations added by filter)
 
        # Map from discount key to itself
 
        # (contains annotations needed in the future)
 
        from_filter = dict((i.id, i) for i in filtered_discounts)
...
 
@@ -173,3 +182,5 @@ class DiscountController(object):
 

	
 
        queryset = queryset.annotate(past_use_count=Sum(past_use_quantity_or_zero))
 
        queryset = queryset.annotate(
 
            past_use_count=Sum(past_use_quantity_or_zero)
 
        )
 
        return queryset
registrasion/controllers/flag.py
Show inline comments
...
 
@@ -230,8 +230,15 @@ class FlagCounter(_FlagCounter):
 

	
 
        types = (conditions.FlagBase.ENABLE_IF_TRUE, conditions.FlagBase.DISABLE_IF_FALSE)
 
        types = (
 
            conditions.FlagBase.ENABLE_IF_TRUE,
 
            conditions.FlagBase.DISABLE_IF_FALSE,
 
        )
 
        keys = ("eit", "dif")
 
        flags = [
 
            flagbases.filter(condition=condition_type
 
            ).values('products', 'categories'
 
            ).annotate(count=Count('id'))
 
            flagbases.filter(
 
                condition=condition_type
 
            ).values(
 
                'products', 'categories'
 
            ).annotate(
 
                count=Count('id')
 
            )
 
            for condition_type in types
registrasion/controllers/product.py
Show inline comments
...
 
@@ -7,3 +7,2 @@ from registrasion.models import inventory
 
from .category import CategoryController
 
from .conditions import ConditionController
 
from .flag import FlagController
registrasion/tests/test_cart.py
Show inline comments
...
 
@@ -28,3 +28,3 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
 
    def tearDown(self):
 
        if False:
 
        if True:
 
            # If you're seeing segfaults in tests, enable this.
registrasion/tests/test_ceilings.py
Show inline comments
...
 
@@ -151,3 +151,7 @@ class CeilingsTestCases(RegistrationCartTestCase):
 

	
 
        discounts = DiscountController.available_discounts(self.USER_1, [], [self.PROD_1])
 
        discounts = DiscountController.available_discounts(
 
            self.USER_1,
 
            [],
 
            [self.PROD_1],
 
        )
 

	
registrasion/tests/test_discount.py
Show inline comments
...
 
@@ -247,3 +247,7 @@ class DiscountTestCase(RegistrationCartTestCase):
 
    def test_enumerate_no_discounts_for_no_input(self):
 
        discounts = DiscountController.available_discounts(self.USER_1, [], [])
 
        discounts = DiscountController.available_discounts(
 
            self.USER_1,
 
            [],
 
            [],
 
        )
 
        self.assertEqual(0, len(discounts))
...
 
@@ -260,3 +264,7 @@ class DiscountTestCase(RegistrationCartTestCase):
 

	
 
        discounts = DiscountController.available_discounts(self.USER_1, [self.CAT_2], [])
 
        discounts = DiscountController.available_discounts(
 
            self.USER_1,
 
            [self.CAT_2],
 
            [],
 
        )
 
        self.assertEqual(0, len(discounts))
...
 
@@ -282,3 +290,7 @@ class DiscountTestCase(RegistrationCartTestCase):
 

	
 
        discounts = DiscountController.available_discounts(self.USER_1, [self.CAT_2], [])
 
        discounts = DiscountController.available_discounts(
 
            self.USER_1,
 
            [self.CAT_2],
 
            [],
 
        )
 
        self.assertEqual(1, len(discounts))
...
 
@@ -330,3 +342,7 @@ class DiscountTestCase(RegistrationCartTestCase):
 

	
 
        discounts = DiscountController.available_discounts(self.USER_1, [self.CAT_1], [])
 
        discounts = DiscountController.available_discounts(
 
            self.USER_1,
 
            [self.CAT_1],
 
            [],
 
        )
 
        self.assertEqual(0, len(discounts))
...
 
@@ -340,3 +356,7 @@ class DiscountTestCase(RegistrationCartTestCase):
 

	
 
        discounts = DiscountController.available_discounts(self.USER_1, [self.CAT_2], [])
 
        discounts = DiscountController.available_discounts(
 
            self.USER_1,
 
            [self.CAT_2],
 
            [],
 
        )
 
        self.assertEqual(2, discounts[0].quantity)
...
 
@@ -351,3 +371,7 @@ class DiscountTestCase(RegistrationCartTestCase):
 

	
 
        discounts = DiscountController.available_discounts(self.USER_1, [self.CAT_2], [])
 
        discounts = DiscountController.available_discounts(
 
            self.USER_1,
 
            [self.CAT_2],
 
            [],
 
        )
 
        self.assertEqual(1, discounts[0].quantity)
...
 
@@ -358,3 +382,7 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        self.test_discount_quantity_is_correct_after_first_purchase()
 
        discounts = DiscountController.available_discounts(self.USER_1, [self.CAT_2], [])
 
        discounts = DiscountController.available_discounts(
 
            self.USER_1,
 
            [self.CAT_2],
 
            [],
 
        )
 
        self.assertEqual(0, len(discounts))
registrasion/views.py
Show inline comments
...
 
@@ -429,3 +429,7 @@ def _handle_products(request, category, products, prefix):
 

	
 
    discounts = DiscountController.available_discounts(request.user, [], products)
 
    discounts = DiscountController.available_discounts(
 
        request.user,
 
        [],
 
        products,
 
    )
 

	
0 comments (0 inline, 0 general)