Fix home button routes and login redirects
All checks were successful
Build and Push Docker Image / build (push) Successful in 41s

This commit is contained in:
2026-06-16 09:50:32 +02:00
parent 1188cef7be
commit c8e65146ec
11 changed files with 108 additions and 12 deletions

View File

@@ -89,6 +89,20 @@ class HomePopularProductsTests(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["home_products"]), 6)
@override_settings(
HOME_ADVANTAGES_LEFT_CATEGORY_SLUG="custom-left",
HOME_ADVANTAGES_RIGHT_CATEGORY_SLUG="custom-right",
)
def test_home_advantages_buttons_use_configured_category_slugs(self):
Category.objects.create(name="Custom left", slug="custom-left")
Category.objects.create(name="Custom right", slug="custom-right")
response = self.client.get(reverse("home"))
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'href="/catalog/custom-left/?new=1"', html=False)
self.assertContains(response, 'href="/catalog/custom-right/?sale=1"', html=False)
class FaviconTests(SimpleTestCase):
def test_favicon_route_returns_icon(self):

View File

@@ -1,4 +1,5 @@
import logging
from urllib.parse import urlencode
from django.conf import settings
from django.core.mail import send_mail
@@ -9,7 +10,7 @@ from django.contrib import messages
from favorites.services import get_user_favorite_item_ids
from home.forms import FaqQuestionForm
from items.models import Item
from items.models import Category, Item
from orders.services import get_user_cart_item_ids
@@ -29,6 +30,19 @@ CONTACT_MAP_EXTERNAL_URL = (
)
def build_home_category_url(category_slug: str, **query_params: str) -> str:
normalized_slug = (category_slug or "").strip().lower()
base_url = "/catalog/"
if normalized_slug and Category.objects.filter(slug=normalized_slug).exists():
base_url = f"/catalog/{normalized_slug}/"
clean_query_params = {key: value for key, value in query_params.items() if value}
if not clean_query_params:
return base_url
return f"{base_url}?{urlencode(clean_query_params)}"
def index(request):
form = FaqQuestionForm(request.POST or None)
@@ -76,6 +90,14 @@ def index(request):
return render(request=request, template_name='home/index.html', context={
"faq_form": form,
"home_products": home_products,
"home_advantages_left_url": build_home_category_url(
settings.HOME_ADVANTAGES_LEFT_CATEGORY_SLUG,
new="1",
),
"home_advantages_right_url": build_home_category_url(
settings.HOME_ADVANTAGES_RIGHT_CATEGORY_SLUG,
sale="1",
),
"favorite_item_ids": get_user_favorite_item_ids(request.user),
"cart_item_ids": get_user_cart_item_ids(request.user),
})