fixed broken links in main/sidemenu when using server_dir '/'

This commit is contained in:
fonfon 2014-07-09 03:15:39 +00:00
parent d4d6948eb9
commit 32872cea12
4 changed files with 14 additions and 9 deletions

2
cfg.py
View File

@ -19,7 +19,7 @@ host = None
port = None
debug = False
no_daemon = False
server_dir = ''
server_dir = '/'
main_menu = Menu()

View File

@ -1,4 +1,5 @@
from urlparse import urlparse
import util
import cfg
@ -31,7 +32,7 @@ class Menu(object):
def find(self, url, basehref=True):
"""Return a menu item with given URL"""
if basehref and url.startswith('/'):
url = cfg.server_dir + url
url = util.rel_urljoin([cfg.server_dir, url])
for item in self.items:
if item.url == url:
@ -51,7 +52,8 @@ class Menu(object):
cfg.server_dir to it"""
if basehref and url.startswith("/"):
url = cfg.server_dir + url
url = util.rel_urljoin([cfg.server_dir, url])
#url = cfg.server_dir + url
item = Menu(label=label, icon=icon, url=url, order=order)
self.items.append(item)

View File

@ -59,11 +59,11 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a href="{{ basehref }}/" class="logo-top">
<a href="{{ basehref }}" class="logo-top">
<img src="{% static 'theme/img/freedombox-logo-32px.png' %}"
alt="FreedomBox" />
</a>
<a class="brand" href="{{ basehref }}/">FreedomBox</a>
<a class="brand" href="{{ basehref }}">FreedomBox</a>
{% block add_nav_and_login %}
<div class="nav-collapse">
<ul class="nav">

11
util.py
View File

@ -12,17 +12,20 @@ class PlinthRedirect(HttpResponseRedirect):
"""
def __init__(self, redirect_to, *args, **kwargs):
if not redirect_to.startswith(cfg.server_dir):
redirect_to = urljoin([cfg.server_dir, redirect_to])
redirect_to = rel_urljoin([cfg.server_dir, redirect_to])
return super(PlinthRedirect, self).__init__(redirect_to,
*args, **kwargs)
def urljoin(parts):
def rel_urljoin(parts, prepend_slash=True):
"""
urllibs' urljoin joins ("foo", "/bar") to "/bar".
Instead, just concatenate the parts with "/" to i.e. /foo/bar
Instead concatenate the parts with "/" to i.e. /foo/bar
"""
return '/' + '/'.join(s.strip('/') for s in parts)
url = '/'.join(s.strip('/') for s in parts)
if prepend_slash and not url.startswith('/'):
url = '/' + url
return url
def mkdir(newdir):