-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serve utn.se/admin at admin.utn.se (#798)
* A Proof of concept solution to server django admin page at admin.domain.com Can be used to show wagtail admin (probably). Uses 'django-host' to server subdomain * Changed to wagtail admin page * Fixed configs so default is used * fix login paths for admin, redirect /admin to admin subdomain * fix comments * support reversing admin paths * fix tests --------- Co-authored-by: [ludvigalden](https://github.com/ludvigalden) and [hato1883](https://github.com/hato1883)
- Loading branch information
Showing
9 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
from django.conf.urls import include, url | ||
|
||
from wagtail.admin import urls as wagtailadmin_urls | ||
|
||
from moore.urls import urlpatterns as base_urlpatterns | ||
|
||
# Use the same `urlpatterns` as other domains as the base | ||
urlpatterns = base_urlpatterns.copy() | ||
|
||
# Insert `wagtailadmin_urls` at appropriate level | ||
urlpatterns.insert( | ||
len(urlpatterns) - 3, | ||
url(r'', include(wagtailadmin_urls)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.conf import settings | ||
from django_hosts.resolvers import reverse_host | ||
from django.http import HttpResponseRedirect | ||
|
||
|
||
def redirect_admin(request, path): | ||
protocol = 'https' if request.is_secure() else 'http' | ||
host = reverse_host(host='admin') | ||
if getattr(settings, 'HOST_PORT', None): | ||
host = f"{host}:{settings.HOST_PORT}" | ||
return HttpResponseRedirect(f'{protocol}://{host}/{path}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django_hosts import patterns, host | ||
from django.conf import settings | ||
|
||
host_patterns = patterns( | ||
'', | ||
host(r'', settings.ROOT_URLCONF, name='default'), | ||
host(r'admin', 'admin.urls', name='admin'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
BASE_URL = 'https://utn.se' | ||
|
||
ALLOWED_HOSTS = ['.utn.se', '.utnarm.se'] | ||
PARENT_HOST = 'utn.se' | ||
|
||
# Email settings | ||
DEFAULT_FROM_EMAIL = '[email protected]' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
|
||
def delete_urls(urlpatterns: list, delete_name: str): | ||
for index, pattern in enumerate(urlpatterns): | ||
if hasattr(pattern, 'name'): | ||
if pattern.name == delete_name: | ||
# Insert before index | ||
urlpatterns.pop(index) | ||
break | ||
|
||
return urlpatterns |