Changeset - 2b59151429fe
[Not reviewed]
Merge
0 9 1
Christopher Neugebauer - 8 years ago 2016-04-06 22:00:39
chrisjrn@gmail.com
Merge branch 'random_fixes'
10 files changed with 168 insertions and 42 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/cart.py
Show inline comments
...
 
@@ -82,2 +82,7 @@ class CartController(object):
 
        items_in_cart = rego.ProductItem.objects.filter(cart=self.cart)
 
        items_in_cart = items_in_cart.select_related(
 
            "product",
 
            "product__category",
 
        )
 

	
 
        product_quantities = list(product_quantities)
...
 
@@ -285,2 +290,3 @@ class CartController(object):
 
        items = rego.ProductItem.objects.filter(cart=self.cart)
 
        items = items.select_related("product")
 
        products = set(i.product for i in items)
...
 
@@ -304,3 +310,5 @@ class CartController(object):
 

	
 
        product_items = self.cart.productitem_set.all()
 
        product_items = self.cart.productitem_set.all().select_related(
 
            "product", "product__category",
 
        )
 

	
...
 
@@ -312,2 +320,3 @@ class CartController(object):
 
        product_items = self.cart.productitem_set.all()
 
        product_items = product_items.select_related("product")
 
        product_items = product_items.order_by('product__price')
registrasion/controllers/category.py
Show inline comments
...
 
@@ -24,3 +24,3 @@ class CategoryController(object):
 
        if products is AllProducts:
 
            products = rego.Product.objects.all()
 
            products = rego.Product.objects.all().select_related("category")
 

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

	
...
 
@@ -92,8 +93,18 @@ class ConditionController(object):
 
        # Get the conditions covered by the products themselves
 
        all_conditions = [
 
            product.enablingconditionbase_set.select_subclasses() |
 
            product.category.enablingconditionbase_set.select_subclasses()
 

	
 
        prods = (
 
            product.enablingconditionbase_set.select_subclasses()
 
            for product in products
 
        ]
 
        all_conditions = set(itertools.chain(*all_conditions))
 
        )
 
        # Get the conditions covered by their categories
 
        cats = (
 
            category.enablingconditionbase_set.select_subclasses()
 
            for category in set(product.category for product in products)
 
        )
 

	
 
        if products:
 
            # Simplify the query.
 
            all_conditions = reduce(operator.or_, itertools.chain(prods, cats))
 
        else:
 
            all_conditions = []
 

	
...
 
@@ -117,6 +128,10 @@ class ConditionController(object):
 
            ).all()
 
            all_products = set(itertools.chain(cond_products, from_category))
 

	
 
            all_products = cond_products | from_category
 
            all_products = all_products.select_related("category")
 
            # Remove the products that we aren't asking about
 
            all_products = all_products & products
 
            all_products = [
 
                product
 
                for product in all_products
 
                if product in products
 
            ]
 

	
registrasion/controllers/discount.py
Show inline comments
...
 
@@ -15,3 +15,3 @@ class DiscountAndQuantity(object):
 
    def __repr__(self):
 
        print "(discount=%s, clause=%s, quantity=%d)" % (
 
        return "(discount=%s, clause=%s, quantity=%d)" % (
 
            self.discount, self.clause, self.quantity,
...
 
@@ -39,2 +39,12 @@ def available_discounts(user, categories, products):
 

	
 
    product_discounts = product_discounts.select_related(
 
        "product",
 
        "product__category",
 
    )
 

	
 
    all_category_discounts = category_discounts | product_category_discounts
 
    all_category_discounts = all_category_discounts.select_related(
 
        "category",
 
    )
 

	
 
    # The set of all potential discounts
...
 
@@ -42,4 +52,3 @@ def available_discounts(user, categories, products):
 
        product_discounts,
 
        category_discounts,
 
        product_category_discounts,
 
        all_category_discounts,
 
    ))
...
 
@@ -52,2 +61,3 @@ def available_discounts(user, categories, products):
 

	
 

	
 
    for discount in potential_discounts:
...
 
@@ -65,3 +75,3 @@ def available_discounts(user, categories, products):
 
            cart__released=False,  # You can reuse refunded discounts
 
            discount=discount.discount,
 
            discount=real_discount,
 
        )
registrasion/controllers/product.py
Show inline comments
...
 
@@ -25,2 +25,3 @@ class ProductController(object):
 
            all_products = rego.Product.objects.filter(category=category)
 
            all_products = all_products.select_related("category")
 
        else:
...
 
@@ -29,3 +30,11 @@ class ProductController(object):
 
        if products is not None:
 
            all_products = itertools.chain(all_products, products)
 
            all_products = set(itertools.chain(all_products, products))
 

	
 
        cat_quants = dict(
 
            (
 
                category,
 
                CategoryController(category).user_quantity_remaining(user),
 
            )
 
            for category in set(product.category for product in all_products)
 
        )
 

	
...
 
@@ -34,5 +43,3 @@ class ProductController(object):
 
            for product in all_products
 
            if CategoryController(product.category).user_quantity_remaining(
 
                user
 
            ) > 0
 
            if cat_quants[product.category] > 0
 
            if cls(product).user_quantity_remaining(user) > 0
registrasion/forms.py
Show inline comments
...
 
@@ -57,2 +57,3 @@ class _QuantityBoxProductsForm(_ProductsForm):
 
                help_text=help_text,
 
                min_value=0,
 
            )
registrasion/migrations/0012_auto_20160406_1212.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8 -*-
 
# Generated by Django 1.9.2 on 2016-04-06 12:12
 
from __future__ import unicode_literals
 

	
 
from django.db import migrations, models
 

	
 

	
 
class Migration(migrations.Migration):
 

	
 
    dependencies = [
 
        ('registrasion', '0011_auto_20160401_0943'),
 
    ]
 

	
 
    operations = [
 
        migrations.AlterField(
 
            model_name='cart',
 
            name='active',
 
            field=models.BooleanField(db_index=True, default=True),
 
        ),
 
        migrations.AlterField(
 
            model_name='cart',
 
            name='released',
 
            field=models.BooleanField(db_index=True, default=False),
 
        ),
 
        migrations.AlterField(
 
            model_name='cart',
 
            name='time_last_updated',
 
            field=models.DateTimeField(db_index=True),
 
        ),
 
        migrations.AlterField(
 
            model_name='category',
 
            name='order',
 
            field=models.PositiveIntegerField(db_index=True, verbose_name='Display order'),
 
        ),
 
        migrations.AlterField(
 
            model_name='product',
 
            name='order',
 
            field=models.PositiveIntegerField(db_index=True, verbose_name='Display order'),
 
        ),
 
        migrations.AlterField(
 
            model_name='productitem',
 
            name='quantity',
 
            field=models.PositiveIntegerField(db_index=True),
 
        ),
 
        migrations.AlterIndexTogether(
 
            name='cart',
 
            index_together=set([('active', 'released'), ('released', 'user'), ('active', 'user'), ('active', 'time_last_updated')]),
 
        ),
 
    ]
registrasion/models.py
Show inline comments
...
 
@@ -101,2 +101,3 @@ class Category(models.Model):
 
        verbose_name=("Display order"),
 
        db_index=True,
 
    )
...
 
@@ -149,2 +150,3 @@ class Product(models.Model):
 
        verbose_name=("Display order"),
 
        db_index=True,
 
    )
...
 
@@ -315,2 +317,3 @@ class VoucherDiscount(DiscountBase):
 
        verbose_name=_("Voucher"),
 
        db_index=True,
 
    )
...
 
@@ -460,2 +463,10 @@ class Cart(models.Model):
 

	
 
    class Meta:
 
        index_together = [
 
            ("active", "time_last_updated"),
 
            ("active", "released"),
 
            ("active", "user"),
 
            ("released", "user"),
 
        ]
 

	
 
    def __str__(self):
...
 
@@ -466,7 +477,15 @@ class Cart(models.Model):
 
    vouchers = models.ManyToManyField(Voucher, blank=True)
 
    time_last_updated = models.DateTimeField()
 
    time_last_updated = models.DateTimeField(
 
        db_index=True,
 
    )
 
    reservation_duration = models.DurationField()
 
    revision = models.PositiveIntegerField(default=1)
 
    active = models.BooleanField(default=True)
 
    released = models.BooleanField(default=False)  # Refunds etc
 
    active = models.BooleanField(
 
        default=True,
 
        db_index=True,
 
    )
 
    released = models.BooleanField(
 
        default=False,
 
        db_index=True
 
    )  # Refunds etc
 

	
...
 
@@ -494,3 +513,3 @@ class ProductItem(models.Model):
 
    product = models.ForeignKey(Product)
 
    quantity = models.PositiveIntegerField()
 
    quantity = models.PositiveIntegerField(db_index=True)
 

	
registrasion/templatetags/registrasion_tags.py
Show inline comments
...
 
@@ -32,3 +32,3 @@ def items_pending(context):
 
        cart__active=True,
 
    )
 
    ).select_related("product", "product__category")
 
    return all_items
...
 
@@ -44,3 +44,4 @@ def items_purchased(context, category=None):
 
        cart__active=False,
 
    )
 
        cart__released=False,
 
    ).select_related("product", "product__category")
 

	
...
 
@@ -49,8 +50,8 @@ def items_purchased(context, category=None):
 

	
 
    products = set(item.product for item in all_items)
 
    pq = all_items.values("product").annotate(quantity=Sum("quantity")).all()
 
    products = rego.Product.objects.all()
 
    out = []
 
    for product in products:
 
        pp = all_items.filter(product=product)
 
        quantity = pp.aggregate(Sum("quantity"))["quantity__sum"]
 
        out.append(ProductAndQuantity(product, quantity))
 
    for item in pq:
 
        prod = products.get(pk=item["product"])
 
        out.append(ProductAndQuantity(prod, item["quantity"]))
 
    return out
registrasion/views.py
Show inline comments
...
 
@@ -117,7 +117,16 @@ def guided_registration(request, page_id=0):
 

	
 
        all_products = rego.Product.objects.filter(
 
            category__in=cats,
 
        ).select_related("category")
 

	
 
        available_products = set(ProductController.available_products(
 
            request.user,
 
            products=all_products,
 
        ))
 

	
 
        for category in cats:
 
            products = ProductController.available_products(
 
                request.user,
 
                category=category,
 
            )
 
            products = [
 
                i for i in available_products
 
                if i.category == category
 
            ]
 

	
...
 
@@ -282,11 +291,13 @@ def handle_products(request, category, products, prefix):
 
        cart=current_cart.cart,
 
    )
 
    ).select_related("product")
 
    quantities = []
 
    for product in products:
 
        # Only add items that are enabled.
 
        try:
 
            quantity = items.get(product=product).quantity
 
        except ObjectDoesNotExist:
 
            quantity = 0
 
        quantities.append((product, quantity))
 
    seen = set()
 

	
 
    for item in items:
 
        quantities.append((item.product, item.quantity))
 
        seen.add(item.product)
 

	
 
    zeros = set(products) - seen
 
    for product in zeros:
 
        quantities.append((product, 0))
 

	
...
 
@@ -325,4 +336,8 @@ 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")
 

	
 
    product_quantities = [
 
        (rego.Product.objects.get(pk=i[0]), i[1]) for i in quantities
 
        (products.get(pk=i[0]), i[1]) for i in quantities
 
    ]
0 comments (0 inline, 0 general)