Skip to content

Commit

Permalink
#698 remove se.ProductImages (#703)
Browse files Browse the repository at this point in the history
* Remove se_context.ProductImages in favor of newcontext.ProductImages

* Remove se_context.ProductImages

* Fix imports for newcontext classes
  • Loading branch information
ArtemijRodionov committed Jan 20, 2019
1 parent 7f3bf67 commit 0437448
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 68 deletions.
34 changes: 0 additions & 34 deletions shopelectro/context.py
@@ -1,34 +0,0 @@
import typing

from catalog.context import AbstractProductsListContext
from catalog.models import ProductQuerySet
from images.models import Image

# @todo #683:60m Remove the ProductImages in favor of catalog.newcontext.ProductImages


class ProductImages(AbstractProductsListContext):

@property
def images(self) -> typing.Dict[int, Image]:
assert isinstance(self.products, ProductQuerySet)

images = {}
if self.product_pages:
images = Image.objects.get_main_images_by_pages(
self.product_pages.filter(shopelectro_product__in=self.products)
)

return {
product.id: images.get(product.page)
for product in self.products
}

def get_context_data(self):
return {
'product_images': self.images,
**(
self.super.get_context_data()
if self.super else {}
),
}
46 changes: 12 additions & 34 deletions shopelectro/views/catalog.py
Expand Up @@ -12,7 +12,6 @@
from images.models import Image
from pages import views as pages_views

from shopelectro import context as se_context
from shopelectro import models
from shopelectro.views.helpers import set_csrf_cookie

Expand Down Expand Up @@ -129,31 +128,23 @@ def get_context_data(self, **kwargs):
tile_products = self.product.get_siblings(
offset=settings.PRODUCT_SIBLINGS_COUNT
)
product_images = self.get_images_context_data(tile_products)['product_images']
product_images = self.get_images_context_data(tile_products)

return {
**context_,
**product_images,
'price_bounds': settings.PRICE_BOUNDS,
'group_tags_pairs': self.product.get_params(),
'product_images': product_images,
'tile_products': tile_products,
}

def get_images_context_data(self, products) -> dict:
"""Return images for given products."""
products_to_filter = [self.product, *products]
product_ids_to_filter = [p.id for p in products_to_filter]
return (
se_context.ProductImages(
url_kwargs={},
request=self.request,
page=self.product.page,
products=models.Product.objects.filter(id__in=product_ids_to_filter),
product_pages=models.ProductPage.objects.filter(
shopelectro_product__in=products_to_filter
),
).get_context_data()
)
return newcontext.products.ProductImages(
newcontext.Products(products_to_filter),
Image.objects.all(),
).context()

def render_siblings_on_404(
self, request, **url_kwargs
Expand All @@ -176,9 +167,7 @@ def render_siblings_on_404(
**url_kwargs,
)

context_['product_images'] = (
self.get_images_context_data(siblings)['product_images']
)
context_.update(self.get_images_context_data(siblings))
return render(request, 'catalog/product_404.html', context_, status=404)


Expand All @@ -201,29 +190,18 @@ def get_context_data(self, **kwargs):
if not mobile_view:
tile_products = top_products

images_ctx = newcontext.products.ProductImages(
newcontext.Products(tile_products),
Image.objects.all(),
).context()
return {
**context_,
**images_ctx,
'tile_title': 'ТОП 10 ТОВАРОВ',
'category_tile': settings.MAIN_PAGE_TILE,
'tile_products': tile_products,
'product_images': (
self.get_products_context_data(
products=top_products
)['product_images']
)
}

def get_products_context_data(self, products=None, product_pages=None) -> dict:
return (
se_context.ProductImages(
url_kwargs={}, # Ignore CPDBear
request=self.request,
page=self.object,
products=products or models.Product.objects.all(),
product_pages=product_pages or models.ProductPage.objects.all(),
).get_context_data()
)


@set_csrf_cookie
class CategoryPage(catalog.CategoryPage):
Expand Down

1 comment on commit 0437448

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 0437448 Jan 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 683-0642f414 disappeared from shopelectro/context.py, that's why I closed #698. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.