Browse Source

Add admin URL redirection and update admin links for Dovoodi and Imam Javad

- Introduced a new URL pattern to redirect "/admin/" to the appropriate language-prefixed admin URL.
- Updated admin links for both Dovoodi and Imam Javad to remove language-specific paths, simplifying access.
- Refactored HomeView to streamline the redirection logic based on the current language.
master
mortezaei 3 months ago
parent
commit
dc103d1f08
  1. 1
      config/urls.py
  2. 21
      utils/admin.py

1
config/urls.py

@ -96,6 +96,7 @@ api_patterns = [
# Base URL patterns (common to all domains) # Base URL patterns (common to all domains)
# These patterns are shared by both Imam Javad and Dovoodi sites # These patterns are shared by both Imam Javad and Dovoodi sites
urlpatterns = [ urlpatterns = [
path("admin/", HomeView.as_view(), name="home"), # Redirect to appropriate admin based on domain
path("i18n/", include("django.conf.urls.i18n")), path("i18n/", include("django.conf.urls.i18n")),
path('api/', include(api_patterns)), path('api/', include(api_patterns)),
path('oneapi-translation/', oneapi_translate), path('oneapi-translation/', oneapi_translate),

21
utils/admin.py

@ -130,7 +130,7 @@ class FormulaAdminSite(UnfoldAdminSite):
}, },
{ {
"title": _("Dovoodi Admin"), "title": _("Dovoodi Admin"),
"link": "https://dovodi.newhorizonco.uk/en/dovoodi/admin/",
"link": "https://dovodi.newhorizonco.uk/admin/",
"icon": "diamond", "icon": "diamond",
} }
] ]
@ -236,7 +236,7 @@ class DovoodiAdminSite(UnfoldAdminSite):
}, },
{ {
"title": _("Imam Javad Admin"), "title": _("Imam Javad Admin"),
"link": "https://imamjavad.newhorizonco.uk/en/imam-javad/admin/",
"link": "https://imamjavad.newhorizonco.uk/admin/",
"icon": "diamond", "icon": "diamond",
} }
] ]
@ -464,20 +464,17 @@ def replace_placeholders_with_real_sites():
# This ensures proper CSS loading for admin templates # This ensures proper CSS loading for admin templates
class HomeView(RedirectView): class HomeView(RedirectView):
"""
Redirects /admin/ to the language-prefixed admin URL.
The domain-based routing middleware will handle which admin site to use.
"""
def get_redirect_url(self, *args, **kwargs): def get_redirect_url(self, *args, **kwargs):
host = self.request.get_host()
# دریافت زبان فعلی (پیش‌فرض: en) # دریافت زبان فعلی (پیش‌فرض: en)
language = get_language() or 'en' language = get_language() or 'en'
# دامنه‌های داوودی
dovoodi_domains = ['dovodi.newhorizonco.uk', 'dovoodi.newhorizonco.uk']
# تصمیم‌گیری بر اساس دامنه و برگرداندن URL با prefix زبانی
if any(domain in host for domain in dovoodi_domains):
return f'/{language}/dovoodi/admin/'
else:
return f'/{language}/imam-javad/admin/'
# Now we simply redirect to /language/admin/
# The SiteMiddleware will route to the correct admin based on domain
return f'/{language}/admin/'
# --------------------------------------------------------- # ---------------------------------------------------------
# 4. Dummy Data for Dashboard Charts # 4. Dummy Data for Dashboard Charts

Loading…
Cancel
Save