symposion_app/registrasion/controllers/category.py

27 lines
693 B
Python
Raw Normal View History

from .product import ProductController
from registrasion import models as rego
2016-04-02 02:29:53 +00:00
class AllProducts(object):
pass
2016-04-02 02:29:53 +00:00
class CategoryController(object):
@classmethod
def available_categories(cls, user, products=AllProducts):
''' Returns the categories available to the user. Specify `products` if
you want to restrict to just the categories that hold the specified
products, otherwise it'll do all. '''
if products is AllProducts:
products = rego.Product.objects.all()
available = ProductController.available_products(
user,
products=products,
)
return set(i.category for i in available)