From 858af932715c277005ad71ddce7c13ce2130336e Mon Sep 17 00:00:00 2001 From: Christian Glatthard Date: Tue, 29 Dec 2015 23:00:06 +0100 Subject: [PATCH] SUBDIRECTORY setting added, to make application support url prefixes --- coco/api/urls.py | 2 +- coco/settings.py | 20 +++++++++++++------- coco/urls.py | 9 +++++---- coco/web/api_client_proxy.py | 4 +++- coco/web/templates/web/snippets/navbar.html | 18 +++++++++--------- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/coco/api/urls.py b/coco/api/urls.py index 52e6b54..975903c 100644 --- a/coco/api/urls.py +++ b/coco/api/urls.py @@ -3,7 +3,7 @@ from rest_framework.urlpatterns import format_suffix_patterns urlpatterns = patterns('', - url(r'^$', views.api_root), + url(r'^$', views.api_root, name='api_root'), # /api/users(/)... url(r'^users/?$', views.UserList.as_view(), name="users"), diff --git a/coco/settings.py b/coco/settings.py index b87120d..4a2817d 100644 --- a/coco/settings.py +++ b/coco/settings.py @@ -14,6 +14,9 @@ import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +# custom setting, used to run the application in a subdirectory, +# trailing slash is needed, i.e. 'sub/' +SUBDIRECTORY = '' # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ @@ -46,9 +49,13 @@ 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', - 'django.contrib.staticfiles' + #'django.contrib.sites', + 'django.contrib.staticfiles', ) +# set site id for site framework +# SITE_ID = 1 + MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -117,12 +124,11 @@ 40: 'danger' } - -# LEGACY SETTINGS FROM OLD . NEEDS REFACTORING -LOGIN_URL = '/accounts/login' -LOGIN_REDIRECT_URL = '/accounts/flag' -PUBLIC_URL = '/public/' -USER_GUIDE_URL = '/docs/user-guide/' +# LEGACY SETTINGS FROM OLD IPYNBSRV. NEEDS REFACTORING +LOGIN_URL = '/{}accounts/login'.format(SUBDIRECTORY) +LOGIN_REDIRECT_URL = '/{}accounts/flag'.format(SUBDIRECTORY) +PUBLIC_URL = '/{}public/'.format(SUBDIRECTORY) +USER_GUIDE_URL = '/{}docs/user-guide/'.format(SUBDIRECTORY) VARS_MODULE_PATH = 'coco.core.conf' diff --git a/coco/urls.py b/coco/urls.py index ab09661..1197f34 100644 --- a/coco/urls.py +++ b/coco/urls.py @@ -15,15 +15,16 @@ 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) ''' +from django.conf import settings from coco.admin.admin import admin_site from django.conf.urls import include, url urlpatterns = [ - url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - url(r'^admin/', include(admin_site.urls)), - url(r'^api/', include('coco.api.urls')), - url(r'^', include('coco.web.urls')) + url(r'^{}admin/doc/'.format(settings.SUBDIRECTORY), include('django.contrib.admindocs.urls')), + url(r'^{}admin/'.format(settings.SUBDIRECTORY), include(admin_site.urls)), + url(r'^{}api/'.format(settings.SUBDIRECTORY), include('coco.api.urls')), + url(r'^{}'.format(settings.SUBDIRECTORY), include('coco.web.urls')) ] diff --git a/coco/web/api_client_proxy.py b/coco/web/api_client_proxy.py index 3d5104e..fc71a04 100644 --- a/coco/web/api_client_proxy.py +++ b/coco/web/api_client_proxy.py @@ -1,8 +1,10 @@ from coco.client.clients import HttpClient +from django.core.urlresolvers import reverse def get_httpclient_instance(request): - base_url = "http://localhost/api" + # TODO: make this url dynamic + base_url = 'http://localhost{}'.format(reverse('api_root')) username = request.user.username password = request.session.get('password') return HttpClient(base_url, auth=(username, password)) diff --git a/coco/web/templates/web/snippets/navbar.html b/coco/web/templates/web/snippets/navbar.html index a88f9a6..582f17d 100644 --- a/coco/web/templates/web/snippets/navbar.html +++ b/coco/web/templates/web/snippets/navbar.html @@ -9,17 +9,17 @@ - coco + coco