Skip to content

Commit

Permalink
#708 Fix tags context for category page (#710)
Browse files Browse the repository at this point in the history
* #708  Fix tags context for category page

* #708  Grade refarm dep to `0.4.28`
  • Loading branch information
duker33 committed Jan 27, 2019
1 parent 2543dcd commit 9cae226
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
13 changes: 7 additions & 6 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ services:
# contains refarm-site modules
- $DEPS_DIR
# Thus, you can work with apps related to the refarm-site
# - $REFARM_DIR/catalog:/usr/local/lib/python3.7/site-packages/catalog
# - $REFARM_DIR/images:/usr/local/lib/python3.7/site-packages/images
# - $REFARM_DIR/ecommerce:/usr/local/lib/python3.7/site-packages/ecommerce
# - $REFARM_DIR/pages:/usr/local/lib/python3.7/site-packages/pages
# - $REFARM_DIR/search:/usr/local/lib/python3.7/site-packages/search
# - $REFARM_DIR/refarm_test_utils:/usr/local/lib/python3.7/site-packages/refarm_test_utils
#- $REFARM_DIR/catalog:/usr/local/lib/python3.7/site-packages/catalog
#- $REFARM_DIR/images:/usr/local/lib/python3.7/site-packages/images
#- $REFARM_DIR/ecommerce:/usr/local/lib/python3.7/site-packages/ecommerce
#- $REFARM_DIR/pages:/usr/local/lib/python3.7/site-packages/pages
#- $REFARM_DIR/search:/usr/local/lib/python3.7/site-packages/search
#- $REFARM_DIR/refarm_test_utils:/usr/local/lib/python3.7/site-packages/refarm_test_utils
#- $REFARM_DIR/refarm_pagination:/usr/local/lib/python3.7/site-packages/refarm_pagination

app-drone:
<<: *app-base
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ ua-parser==0.8.0
user-agents==1.1.0
sorl-thumbnail==12.5.0
https://github.com/selwin/django-user_agents/archive/master.zip
https://github.com/fidals/refarm-site/archive/0.4.27.zip
https://github.com/fidals/refarm-site/archive/0.4.28.zip
15 changes: 15 additions & 0 deletions shopelectro/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def test_contains_product_with_certain_tags(self):
models.Product.objects.filter(Q(tags=tags[0]) | Q(tags=tags[1]))
)))

self.assertEqual(
products_count,
response.context['paginated']['total_products']
)
self.assertContains(response, products_count)

def test_tag_titles_content_disjunction(self):
Expand Down Expand Up @@ -215,6 +219,17 @@ def test_non_existing_tags_404(self):
response = self.client.get(bad_tag_url)
self.assertEqual(response.status_code, 404)

def test_category_tag_relation(self):
"""Category page should contain only tags, related to the current category."""
category = models.Category.objects.get(
name='Category #0 of #Category #0 of #Category #0'
)
# category is not related to this tag at DB ...
tag = models.Tag.objects.exclude_by_products(category.products.all()).first()
# ... so category page should not contain this tag
response = self.client.get(category.url)
self.assertNotContains(response, tag.name)


@tag('fast')
class CatalogPagination(BaseCatalogTestCase):
Expand Down
21 changes: 12 additions & 9 deletions shopelectro/views/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ def get_catalog_context(request, page, category, raw_tags, page_number, per_page

# @todo #683:30m Remove *Tags and *Products suffixes from catalog.newcontext classes.
# Rename Checked404Tags to ExistingOr404.
products_by_category = newcontext.products.ProductsByCategory(
category=category,
products=newcontext.products.ActiveProducts(
newcontext.Products(
models.Product.objects.all(),
),
),
)
products = newcontext.products.OrderedProducts(
sorting_index=sorting_index,
products=newcontext.products.TaggedProducts(
tags=selected_tags,
products=newcontext.products.ProductsByCategory(
category=category,
products=newcontext.products.ActiveProducts(
newcontext.Products(
models.Product.objects.all(),
),
),
),
products=products_by_category
),
)

Expand All @@ -68,7 +69,9 @@ def get_catalog_context(request, page, category, raw_tags, page_number, per_page

images = newcontext.products.ProductImages(paginated_products, Image.objects.all())
brands = newcontext.products.ProductBrands(paginated_products, all_tags)
grouped_tags = newcontext.tags.GroupedTags(all_tags)
grouped_tags = newcontext.tags.GroupedTags(
tags=newcontext.tags.TagsByProducts(all_tags, products_by_category.qs())
)
page = se_context.Page(page, selected_tags)

contexts = newcontext.Contexts(page, paginated_products, images, brands, grouped_tags)
Expand Down

0 comments on commit 9cae226

Please sign in to comment.