diff --git a/menu.py b/menu.py index 94514141f..be526ae03 100644 --- a/menu.py +++ b/menu.py @@ -28,12 +28,14 @@ class Menu(object): self.icon = icon self.url = url self.order = order + # TODO: With an ordered dictionary for self.items we could access the + # items by their URL directly instead of searching for them each time, + # which we do currently with the 'get' method self.items = [] def get(self, urlname, url_args=None, url_kwargs=None): """Return a menu item with given URL name""" url = reverse(urlname, args=url_args, kwargs=url_kwargs) - url = util.rel_urljoin([cfg.server_dir, url]) for item in self.items: if item.url == url: return item @@ -48,14 +50,12 @@ class Menu(object): """ Add a named URL to the menu (via add_item) url_args and url_kwargs will be passed on to url reverse """ url = reverse(urlname, args=url_args, kwargs=url_kwargs) - return self.add_item(label, icon, url, order, add_url_prefix=True) + return self.add_item(label, icon, url, order) - def add_item(self, label, icon, url, order=50, add_url_prefix=False): + def add_item(self, label, icon, url, order=50): """This method creates a menu item with the parameters, adds that menu item to this menu, and returns the item. """ - if add_url_prefix: - url = util.rel_urljoin([cfg.server_dir, url]) item = Menu(label=label, icon=icon, url=url, order=order) self.items.append(item) self.sort_items() diff --git a/modules/lib/urls.py b/modules/lib/urls.py index 2414b705a..02321e7b8 100644 --- a/modules/lib/urls.py +++ b/modules/lib/urls.py @@ -20,6 +20,7 @@ URLs for the Lib module """ from django.conf.urls import patterns, url +from django.core.urlresolvers import reverse_lazy import cfg @@ -28,5 +29,5 @@ urlpatterns = patterns( # pylint: disable-msg=C0103 url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='login'), url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', - {'next_page': cfg.server_dir}, name='logout') + {'next_page': reverse_lazy('index')}, name='logout') ) diff --git a/plinth.py b/plinth.py index 13f425076..816bc977b 100755 --- a/plinth.py +++ b/plinth.py @@ -126,6 +126,12 @@ def context_processor(request): def configure_django(): """Setup Django configuration in the absense of .settings file""" + + # In module_loader.py we reverse URLs for the menu without having a proper + # request. In this case, get_script_prefix (used by reverse) returns the + # wrong prefix. Set it here manually to have the correct prefix right away. + django.core.urlresolvers.set_script_prefix(cfg.server_dir) + context_processors = [ 'django.contrib.auth.context_processors.auth', 'django.core.context_processors.debug', @@ -179,9 +185,9 @@ def configure_django(): 'django.contrib.contenttypes', 'django.contrib.messages'], LOGGING=logging_configuration, - LOGIN_URL=cfg.server_dir + '/accounts/login/', - LOGIN_REDIRECT_URL=cfg.server_dir + '/', - LOGOUT_URL=cfg.server_dir + '/accounts/logout/', + LOGIN_URL='lib:login', + LOGIN_REDIRECT_URL='apps:index', + LOGOUT_URL='lib:logout', MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', diff --git a/util.py b/util.py index 3bb0499ce..b593fb8d8 100644 --- a/util.py +++ b/util.py @@ -1,17 +1,6 @@ import os -def rel_urljoin(parts, prepend_slash=True): - """ - urllibs' urljoin joins ("foo", "/bar") to "/bar". - Instead concatenate the parts with "/" to i.e. /foo/bar - """ - url = '/'.join(s.strip('/') for s in parts) - if prepend_slash and not url.startswith('/'): - url = '/' + url - return url - - def mkdir(newdir): """works the way a good mkdir should :) - already exists, silently complete