Skip to content
Browse files

Merge branch 'master' of github.com:dokterbob/django-shopkit

  • Loading branch information...
2 parents b553035 + a07388e commit ca490daa3cb44d4b557055c0b2219a48bb295bea @dokterbob dokterbob committed Mar 1, 2012
Showing with 20 additions and 7 deletions.
  1. +10 −1 shopkit/category/basemodels.py
  2. +10 −6 shopkit/core/models.py
View
11 shopkit/category/basemodels.py
@@ -177,8 +177,10 @@ def __unicode__(self):
logger.debug(u'Enabling MPTTCategoryBase with category tree optimalization')
from mptt.models import MPTTModel
+ from mptt.managers import TreeManager
class MPTTCategoryBase(MPTTModel, NestedCategoryBase):
+ tree = TreeManager()
class Meta(MPTTModel.Meta, NestedCategoryBase.Meta):
abstract = True
@@ -210,7 +212,14 @@ def get_products(self):
in_shop = product_class.in_shop
descendants = self.get_descendants(include_self=True)
- return in_shop.filter(categories__in=descendants).distinct()
+ # To do: Create in_category manager for products to circumvent
+ # this awkward lookup
+ if hasattr(product_class, 'categories'):
+ return in_shop.filter(categories__in=descendants).distinct()
+ else:
+ # Distinct not necessary - product can only be in one
+ # category. Haha.
+ return in_shop.filter(category__in=descendants)
def __unicode__(self):
""" The unicode representation of a nested category is that of
View
16 shopkit/core/models.py
@@ -128,7 +128,7 @@ def get_order_line(self):
def get_parent(self):
"""
- Get the relevant Cart. Used to have a generic API for Carts
+ Get the relevant Cart. Used to have a generic API for Carts
and Orders.
"""
return self.cart
@@ -168,11 +168,15 @@ def from_request(cls, request):
if not cart.customer and request.user.is_authenticated():
try:
- customer = request.user.customer
+ if hasattr(request.user, 'customer'):
+ customer = request.user.customer
- logger.debug(u'Setting customer for cart to %s', customer)
+ logger.debug(u'Setting customer for cart to %s', customer)
+
+ cart.customer = customer
+ else:
+ logger.debug(u'Users appear not to have a customer object related to them.')
- cart.customer = customer
except ObjectDoesNotExist:
logger.info(u'User %s logged in but no customer object '+
u'found. This user will not be able to buy '+
@@ -425,7 +429,7 @@ def confirm(self):
def get_parent(self):
"""
- Get the relevant Order. Used to have a generic API for Carts
+ Get the relevant Order. Used to have a generic API for Carts
and Orders.
"""
return self.order
@@ -670,7 +674,7 @@ def confirm(self):
# *does* occur in the process, we do not want to risk being able
# to call `confirm()` again.
self.confirmed = True
-
+
# Make sure the cart is reset in order to preserve referential
# integrity
self.cart = None

0 comments on commit ca490da

Please sign in to comment.
Something went wrong with that request. Please try again.