Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
add a MULTISITE_FALLBACK view to create Alias entry
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Jul 21, 2016
1 parent b6b7c57 commit 7cd404f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pylucid/base_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'TIMEOUT': 60 * 60 * 24, # 24 hours
}

MULTISITE_FALLBACK="pylucid.multisite_views.multisite_fallback_view"


MIDDLEWARE_CLASSES = (
Expand Down
28 changes: 28 additions & 0 deletions pylucid/multisite_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

from django.conf import settings
from django.contrib.sites.models import Site
from django.http import HttpResponseRedirect

from multisite.models import Alias


def multisite_fallback_view(request):
"""
Create a multisite.models.Alias entry for the current host.
Use the default SITE_ID.
Use by add this into settings:
MULTISITE_FALLBACK="pylucid.multisite_views.multisite_fallback_view"
"""
host = request.get_host().lower()
site_id = settings.SITE_ID.get_default()
site = Site.objects.get(pk=site_id)

# print("Create Alias for %r to SITE_ID %s" % (host, site.pk))
Alias.objects.create(
domain=host,
site=site,
redirect_to_canonical=False,
)
return HttpResponseRedirect(request.get_full_path())

0 comments on commit 7cd404f

Please sign in to comment.