Skip to content

Commit

Permalink
#554 Fix tag slug behaviour (#557)
Browse files Browse the repository at this point in the history
* #554  Return 404 for non-existing tags

* #554  Grade refarm version to fix unstable tags slug
  • Loading branch information
duker33 authored Aug 30, 2018
1 parent e96a582 commit e4293d5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ ua-parser==0.8.0
user-agents==1.1.0
sorl-thumbnail==12.4a1
https://github.com/selwin/django-user_agents/archive/master.zip
https://github.com/fidals/refarm-site/archive/0.2.0.zip
https://github.com/fidals/refarm-site/archive/0.2.1.zip
12 changes: 12 additions & 0 deletions shopelectro/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ def test_product_tag_linking(self):
for link in property_links:
self.assertContains(response, link)

def test_non_existing_tags_404(self):
"""Product should contain links on CategoryTagPage for it's every tag."""
product = Product.objects.first()
self.assertGreater(product.tags.count(), 0)

bad_tag_url = reverse('category', kwargs={
'slug': product.category.page.slug,
'tags': 'non-existent-tag',
})
response = self.client.get(bad_tag_url)
self.assertEqual(response.status_code, 404)


class CatalogPagination(BaseCatalogTestCase):

Expand Down
3 changes: 3 additions & 0 deletions shopelectro/views/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ def get_context_data(self, **kwargs):
slugs = models.Tag.parse_url_tags(tags)
tags = models.Tag.objects.filter(slug__in=slugs)

if not tags:
raise http.Http404('No such tag.')

all_products = (
all_products
.filter(tags__in=tags)
Expand Down

0 comments on commit e4293d5

Please sign in to comment.