Skip to content

Commit

Permalink
Move fetching products for homepage to a helper
Browse files Browse the repository at this point in the history
  • Loading branch information
artursmet committed Jan 30, 2017
1 parent bcd0c55 commit d9e9727
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions saleor/core/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.template.response import TemplateResponse

from ..product.utils import products_with_availability, products_with_details
from ..product.utils import products_with_availability, products_for_homepage


def home(request):
products = products_with_details(request.user).filter(is_featured=True)[:8]
products = products_for_homepage()[:8]
products = products_with_availability(
products, discounts=request.discounts, local_currency=request.currency)
return TemplateResponse(
Expand Down
9 changes: 9 additions & 0 deletions saleor/product/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from collections import namedtuple

from django.contrib.auth.models import AnonymousUser

from ..cart.utils import get_cart_from_request, get_or_create_cart_from_request
from ..core.utils import to_local_currency
from .forms import get_form_class_for_product
Expand All @@ -26,6 +28,13 @@ def products_with_details(user):
return products


def products_for_homepage():
user = AnonymousUser()
products = products_with_details(user)
products = products.filter(is_featured=True)
return products


def get_product_images(product):
"""
Returns list of product images that will be placed in product gallery
Expand Down

0 comments on commit d9e9727

Please sign in to comment.