Changeset - 941caa30d9f4
[Not reviewed]
0 2 0
Christopher Neugebauer - 8 years ago 2016-04-30 10:30:21
chrisjrn@gmail.com
Replaces ProductController.attach_user_remainders with ProductController.user_remainders
2 files changed with 9 insertions and 22 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/cart.py
Show inline comments
...
 
@@ -219,5 +219,3 @@ class CartController(object):
 
        # Pre-annotate products
 
        products = [p for (p, q) in product_quantities]
 
        r = ProductController.attach_user_remainders(self.cart.user, products)
 
        with_remainders = dict((p, p) for p in r)
 
        remainders = ProductController.user_remainders(self.cart.user)
 

	
...
 
@@ -228,3 +226,3 @@ class CartController(object):
 

	
 
            limit = with_remainders[product].remainder
 
            limit = remainders[product.id]
 

	
registrasion/controllers/product.py
Show inline comments
...
 
@@ -40,4 +40,3 @@ class ProductController(object):
 

	
 
        r = ProductController.attach_user_remainders(user, all_products)
 
        prod_quants = dict((p, p) for p in r)
 
        product_remainders = ProductController.user_remainders(user)
 

	
...
 
@@ -47,3 +46,3 @@ class ProductController(object):
 
            if cat_quants[product.category].remainder > 0
 
            if prod_quants[product].remainder > 0
 
            if product_remainders[product.id] > 0
 
        )
...
 
@@ -61,3 +60,3 @@ class ProductController(object):
 
    @classmethod
 
    def attach_user_remainders(cls, user, products):
 
    def user_remainders(cls, user):
 
        '''
...
 
@@ -65,9 +64,7 @@ class ProductController(object):
 
        Return:
 
            queryset(inventory.Product): A queryset containing items from
 
            ``product``, with an extra attribute -- remainder = the amount of
 
            this item that is remaining.
 
            Mapping[int->int]: A dictionary that maps the product ID to the
 
            user's remainder for that product.
 
        '''
 

	
 
        ids = [product.id for product in products]
 
        products = inventory.Product.objects.filter(id__in=ids)
 
        products = inventory.Product.objects.all()
 

	
...
 
@@ -95,10 +92,2 @@ class ProductController(object):
 

	
 
        return products
 

	
 
    def user_quantity_remaining(self, user):
 
        ''' Returns the quantity of this product that the user add in the
 
        current cart. '''
 

	
 
        with_remainders = self.attach_user_remainders(user, [self.product])
 

	
 
        return with_remainders[0].remainder
 
        return dict((product.id, product.remainder) for product in products)
0 comments (0 inline, 0 general)