Skip to content

Commit

Permalink
SUBDIRECTORY setting added, to make application support url prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Glatthard committed Dec 29, 2015
1 parent 17c0f6d commit 858af93
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion coco/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
20 changes: 13 additions & 7 deletions coco/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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'

Expand Down
9 changes: 5 additions & 4 deletions coco/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
]


Expand Down
4 changes: 3 additions & 1 deletion coco/web/api_client_proxy.py
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
18 changes: 9 additions & 9 deletions coco/web/templates/web/snippets/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">coco</a>
<a class="navbar-brand" href="{% url 'dashboard' %}">coco</a>
</div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="/">Dashboard</a></li>
<li><a href="/containers">Containers</a></li>
<li><a href="/images">Images</a></li>
<li><a href="/shares">Shares</a></li>
<li><a href="/groups">Groups</a></li>
<li><a href="/notifications">Notifications {% if new_notifications_count >= 0 %}<span id="notification_bubble">{{ new_notifications_count }}</span>{% endif %}</a></li>
<li><a href="{% url 'dashboard' %}">Dashboard</a></li>
<li><a href="{% url 'containers' %}">Containers</a></li>
<li><a href="{% url 'images' %}">Images</a></li>
<li><a href="{% url 'shares' %}">Shares</a></li>
<li><a href="{% url 'groups' %}">Groups</a></li>
<li><a href="{% url 'notifications' %}">Notifications {% if new_notifications_count >= 0 %}<span id="notification_bubble">{{ new_notifications_count }}</span>{% endif %}</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="hidden-xs"><a href="{% settings 'USER_GUIDE_URL' %}" data-tooltip data-placement="bottom" title="User Guide" target="_blank">
Expand All @@ -28,7 +28,7 @@
<li class="hidden-xs"><a href="{% settings 'PUBLIC_URL' %}{{ request.user.get_username }}" data-tooltip data-placement="bottom" title="My publications" target="_blank">
<i class="glyphicon glyphicon-globe" aria-hidden="true"></i>
</a></li>
<li class="hidden-xs"><a href="/accounts/unflag" data-tooltip data-placement="bottom" title="Logout">
<li class="hidden-xs"><a href="{% url 'accounts_unflag' %}" data-tooltip data-placement="bottom" title="Logout">
<i class="glyphicon glyphicon-log-out" aria-hidden="true"></i>
</a></li>
<li class="hidden-sm hidden-md hidden-lg">
Expand All @@ -38,7 +38,7 @@
<a href="{% settings 'PUBLIC_URL' %}{{ request.user.get_username }}" title="My publications" target="_blank">My publications</a>
</li>
<li class="hidden-sm hidden-md hidden-lg">
<a href="/accounts/unflag" title="Logout">Logout</a>
<a href="{% url 'accounts_unflag' %}" title="Logout">Logout</a>
</li>
</ul>
</div>
Expand Down

0 comments on commit 858af93

Please sign in to comment.