Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support multisite switch via domain name #873

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion taccsite_cms/custom_app_settings.example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CUSTOM_APPS = ['apps.custom_example']
CUSTOM_MIDDLEWARE = []
CUSTOM_MIDDLEWARE = ['taccsite_cms.middleware.settings.SiteIdMiddleware']
STATICFILES_DIRS = ()
20 changes: 20 additions & 0 deletions taccsite_cms/middleware/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Change site based on domain name (fallback to default site)"""
from django.conf import settings
from urllib.parse import urlparse
from django.contrib.sites.models import Site

class SiteIdMiddleware:
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
try:
current_site = Site.objects.get(domain=request.get_host())
except Site.DoesNotExist:
current_site = Site.objects.get(id=settings.DEFAULT_SITE_ID)

request.current_site = current_site
settings.SITE_ID = current_site.id

response = self.get_response(request)
return response
4 changes: 4 additions & 0 deletions taccsite_cms/settings_local.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@
# To disable the Core-Portal integration
PORTAL_IS_TACC_CORE_PORTAL = False
PORTAL_HAS_LOGIN = False

# To allow login in unique situations
# FAQ: If `BLOG_MULTISITE = True`, set `SESSION_COOKIE_SECURE=False` to be able to log in to CMS Admin at different domain (e.g. 0.0.0.0)
SESSION_COOKIE_SECURE = False