fix the middleware issue

This commit is contained in:
ismail 2025-06-26 12:00:16 +03:00
parent 3a5ab31f83
commit c9fad7b79c
5 changed files with 7 additions and 17 deletions

View File

@ -124,8 +124,7 @@ class DealerSlugMiddleware:
def process_view(self, request, view_func, view_args, view_kwargs):
if request.user.is_authenticated:
dealer = get_user_type(request)
if "dealer_slug" not in view_kwargs:
return redirect("home", dealer_slug=dealer.slug, **view_kwargs)
elif view_kwargs["dealer_slug"] != dealer.slug:
raise Http404("Dealer slug mismatch")
if view_kwargs.get("dealer_slug"):
if view_kwargs["dealer_slug"] != dealer.slug:
raise Http404("Dealer slug mismatch")
return None

View File

@ -9,7 +9,7 @@ from django.conf.urls import handler403, handler400, handler404, handler500
urlpatterns = [
# main URLs
path("", views.HomeView.as_view(), name="home"),
path("<slug:dealer_slug>/", views.HomeView.as_view(), name="home"),
# path("<slug:dealer_slug>/", views.HomeView.as_view(), name="home"),
path("welcome/", views.WelcomeView.as_view(), name="welcome"),
# Accounts URLs
# path("login/", allauth_views.LoginView.as_view(template_name="account/login.html"), name="account_login"),

View File

@ -349,15 +349,6 @@ class HomeView(LoginRequiredMixin, TemplateView):
template_name = "index.html"
def dispatch(self, request, *args, **kwargs):
# Redirect unauthenticated users to the welcome page
if not request.user.is_authenticated:
return redirect("welcome")
if not kwargs.get("dealer_slug"):
dealer = get_user_type(request)
return redirect("home", dealer_slug=dealer.slug)
return super().dispatch(request, *args, **kwargs)
class TestView(TemplateView):
"""

View File

@ -12,7 +12,7 @@
<div class="row justify-content-between mb-2">
<div class="col-6 col-md-4 col-xxl-2 text-center border-translucent border-start-xxl border-end-xxl-0 border-bottom-xxl-0 border-end border-bottom pb-4 pb-xxl-0 ">
<span class="uil fs-5 lh-1 uil-users-alt text-success"></span>
<a href="{% url 'user_list request.dealer.slug' %}"><h4 class="fs-6 pt-3">{{ staff }}</h4></a>
<a href="{% url 'user_list' request.dealer.slug %}"><h4 class="fs-6 pt-3">{{ staff }}</h4></a>
<p class="fs-9 mb-0">{{ _("Staff")}}</p>
</div>
<div class="col-6 col-md-4 col-xxl-2 text-center border-translucent border-start-xxl border-end-xxl-0 border-bottom-xxl-0 border-end border-bottom pb-4 pb-xxl-0 ">
@ -32,7 +32,7 @@
</div>
<div class="col-6 col-md-4 col-xxl-2 text-center border-translucent border-start-xxl border-end-xxl-0 border-bottom-xxl-0 border-end border-bottom pb-4 pb-xxl-0 ">
<span class="uil fs-5 lh-1 uil-comment-alt-question text-success-dark"></span>
<a href="{% url 'estimate_list' %}"><h4 class="fs-6 pt-3">{{ estimates }}</h4></a>
<a href="{% url 'estimate_list' request.dealer.slug %}"><h4 class="fs-6 pt-3">{{ estimates }}</h4></a>
<p class="fs-9 mb-0">{{ _("Quotations")}}</p>
</div>
<div class="col-6 col-md-4 col-xxl-2 text-center border-translucent border-start-xxl border-end-xxl-0 border-bottom-xxl-0 border-end border-bottom pb-4 pb-xxl-0 ">

View File

@ -358,7 +358,7 @@
aria-label="Toggle Navigation">
<span class="navbar-toggle-icon"><span class="toggle-line"></span></span>
</button>
<a class="navbar-brand me-1 me-sm-3" href="{% url 'home' request.dealer.slug %}">
<a class="navbar-brand me-1 me-sm-3" href="{% url 'home' %}">
<div class="d-flex align-items-center">
<img class="logo-img d-dark-none" src="{% static 'images/logos/logo-d.png' %}" alt="haikal" width="27" />
<img class="logo-img d-light-none" src="{% static 'images/logos/logo.png' %}" alt="haikal" width="27" />