diff --git a/network-api/networkapi/buyersguide/templates/bg_base.html b/network-api/networkapi/buyersguide/templates/bg_base.html index b64834757ae..173e0850912 100644 --- a/network-api/networkapi/buyersguide/templates/bg_base.html +++ b/network-api/networkapi/buyersguide/templates/bg_base.html @@ -93,7 +93,7 @@ {% block guts %}{% endblock %} - {% include "partials/footer.html" with exclude_language_switcher=True %} + {% include "partials/footer.html" %} {% block extra_scripts %}{% endblock %} diff --git a/network-api/networkapi/buyersguide/tests.py b/network-api/networkapi/buyersguide/tests.py index ebf515b7669..710e7540ff7 100644 --- a/network-api/networkapi/buyersguide/tests.py +++ b/network-api/networkapi/buyersguide/tests.py @@ -9,7 +9,7 @@ from datetime import date from networkapi.buyersguide.factory import ProductFactory -from networkapi.buyersguide.models import RangeVote, BooleanVote, Product, BuyersGuideProductCategory +from networkapi.buyersguide.models import RangeVote, BooleanVote, Product from networkapi.buyersguide.views import product_view, category_view, buyersguide_home from django.core.management import call_command @@ -328,33 +328,25 @@ def test_homepage(self): def test_localised_homepage(self): """ - Test that the homepage redirects when missing a locale code. + Test that the homepage redirects properly under different locale configurations. """ response = self.client.get('/privacynotincluded/') self.assertEqual(response.status_code, 302, 'simple locale gets redirected') - def test_only_en(self): - """ - Test that the homepage redirects away from the other locales the site supports - """ - response = self.client.get('/fr/privacynotincluded', follow=True) - self.assertEqual(response.redirect_chain[1][0], '/en/privacynotincluded/', 'redirects /fr/ to /en/') - self.assertEqual(response.status_code, 200) - - response = self.client.get('/de/privacynotincluded', follow=True) - self.assertEqual(response.redirect_chain[1][0], '/en/privacynotincluded/', 'redirects /de/ to /en/') - self.assertEqual(response.status_code, 200) - - response = self.client.get('/pt/privacynotincluded', follow=True) - self.assertEqual(response.redirect_chain[1][0], '/en/privacynotincluded/', 'redirects /pt/ to /en/') + response = self.client.get('/privacynotincluded', follow=True, HTTP_ACCEPT_LANGUAGE='fr') + self.assertEqual( + response.redirect_chain[0][0], + '/fr/privacynotincluded/', + 'redirects according to HTTP_ACCEPT_LANGUAGE' + ) self.assertEqual(response.status_code, 200) - response = self.client.get('/es/privacynotincluded', follow=True) - self.assertEqual(response.redirect_chain[1][0], '/en/privacynotincluded/', 'redirects /es/ to /en/') + response = self.client.get('/privacynotincluded', follow=True, HTTP_ACCEPT_LANGUAGE='foo') + self.assertEqual(response.redirect_chain[0][0], '/en/privacynotincluded/', 'redirects to /en/ by default') self.assertEqual(response.status_code, 200) - response = self.client.get('/pl/privacynotincluded', follow=True) - self.assertEqual(response.redirect_chain[1][0], '/en/privacynotincluded/', 'redirects /pl/ to /en/') + response = self.client.get('/de/privacynotincluded', follow=True, HTTP_ACCEPT_LANGUAGE='it') + self.assertEqual(response.redirect_chain[0][0], '/de/privacynotincluded/', 'no redirect from hardcoded locale') self.assertEqual(response.status_code, 200) def test_product_view_404(self): @@ -411,39 +403,3 @@ def name_change_changes_slug(self): p.name = 'name changed' p.save() self.assertEqual(p.slug, slugify(p.name)) - - def test_only_en(self): - p = Product.objects.create(name='this should redirect', review_date=date.today()) - url = f'/fr/privacynotincluded/products/{p.slug}/' - response = self.client.get(url) - self.assertEqual(response.status_code, 302) - self.assertEqual( - response['Location'], - f'/en/privacynotincluded/products/{p.slug}/', - 'redirects to /en/privacynotincluded/products/{slug}/' - ) - - -class CategoryViewTest(TestCase): - def test_only_en(self): - c = BuyersGuideProductCategory.objects.create(name='testcategory') - url = f'/fr/privacynotincluded/categories/{c.name}/' - response = self.client.get(url) - self.assertEqual(response.status_code, 302) - self.assertEqual( - response['Location'], - f'/en/privacynotincluded/categories/{c.name}/', - 'redirects to /en/privacynotincluded/categories/{name}/' - ) - - -class AboutViewTest(TestCase): - def test_only_en(self): - url = f'/fr/privacynotincluded/about/' - response = self.client.get(url) - self.assertEqual(response.status_code, 302) - self.assertEqual( - response['Location'], - f'/en/privacynotincluded/about/', - 'redirects to /en/privacynotincluded/about/' - ) diff --git a/network-api/networkapi/buyersguide/views.py b/network-api/networkapi/buyersguide/views.py index ce85a929ef4..164f04c8872 100644 --- a/network-api/networkapi/buyersguide/views.py +++ b/network-api/networkapi/buyersguide/views.py @@ -41,26 +41,6 @@ def get_average_creepiness(product): return 50 -def path_is_en_prefixed(path): - return path.startswith('/en/') - - -def get_en_redirect(path): - redirect_path = re.sub(locale_regex, '/en/', path) - return redirect(redirect_path, permanent=False) - - -def enforce_en_locale(view_handler): - def check_locale(*args, **kwargs): - path = args[0].path - if not path_is_en_prefixed(path): - return get_en_redirect(path) - - return view_handler(*args, **kwargs) - - return check_locale - - def filter_draft_products(request, products): if request.user.is_authenticated: return products @@ -69,7 +49,6 @@ def filter_draft_products(request, products): @redirect_to_default_cms_site -@enforce_en_locale def buyersguide_home(request): products = cache.get('sorted_product_dicts') @@ -88,7 +67,6 @@ def buyersguide_home(request): @redirect_to_default_cms_site -@enforce_en_locale def category_view(request, slug): key = f'products_category__{slug}' products = cache.get(key) @@ -114,7 +92,6 @@ def category_view(request, slug): @redirect_to_default_cms_site -@enforce_en_locale def product_view(request, slug): product = get_object_or_404(Product, slug=slug) @@ -152,7 +129,6 @@ def product_view(request, slug): def bg_about_page(template_name): @redirect_to_default_cms_site - @enforce_en_locale def render_view(request): key = 'categories' categories = cache.get(key)