mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
removed all manual url prefix handling, we only use djangos url system now
This commit is contained in:
parent
0e18fe3c1c
commit
0d0c9f7bb0
10
menu.py
10
menu.py
@ -28,12 +28,14 @@ class Menu(object):
|
|||||||
self.icon = icon
|
self.icon = icon
|
||||||
self.url = url
|
self.url = url
|
||||||
self.order = order
|
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 = []
|
self.items = []
|
||||||
|
|
||||||
def get(self, urlname, url_args=None, url_kwargs=None):
|
def get(self, urlname, url_args=None, url_kwargs=None):
|
||||||
"""Return a menu item with given URL name"""
|
"""Return a menu item with given URL name"""
|
||||||
url = reverse(urlname, args=url_args, kwargs=url_kwargs)
|
url = reverse(urlname, args=url_args, kwargs=url_kwargs)
|
||||||
url = util.rel_urljoin([cfg.server_dir, url])
|
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
if item.url == url:
|
if item.url == url:
|
||||||
return item
|
return item
|
||||||
@ -48,14 +50,12 @@ class Menu(object):
|
|||||||
""" Add a named URL to the menu (via add_item)
|
""" Add a named URL to the menu (via add_item)
|
||||||
url_args and url_kwargs will be passed on to url reverse """
|
url_args and url_kwargs will be passed on to url reverse """
|
||||||
url = reverse(urlname, args=url_args, kwargs=url_kwargs)
|
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
|
"""This method creates a menu item with the parameters, adds
|
||||||
that menu item to this menu, and returns the item.
|
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)
|
item = Menu(label=label, icon=icon, url=url, order=order)
|
||||||
self.items.append(item)
|
self.items.append(item)
|
||||||
self.sort_items()
|
self.sort_items()
|
||||||
|
|||||||
@ -20,6 +20,7 @@ URLs for the Lib module
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from django.conf.urls import patterns, url
|
from django.conf.urls import patterns, url
|
||||||
|
from django.core.urlresolvers import reverse_lazy
|
||||||
|
|
||||||
import cfg
|
import cfg
|
||||||
|
|
||||||
@ -28,5 +29,5 @@ urlpatterns = patterns( # pylint: disable-msg=C0103
|
|||||||
url(r'^accounts/login/$', 'django.contrib.auth.views.login',
|
url(r'^accounts/login/$', 'django.contrib.auth.views.login',
|
||||||
{'template_name': 'login.html'}, name='login'),
|
{'template_name': 'login.html'}, name='login'),
|
||||||
url(r'^accounts/logout/$', 'django.contrib.auth.views.logout',
|
url(r'^accounts/logout/$', 'django.contrib.auth.views.logout',
|
||||||
{'next_page': cfg.server_dir}, name='logout')
|
{'next_page': reverse_lazy('index')}, name='logout')
|
||||||
)
|
)
|
||||||
|
|||||||
12
plinth.py
12
plinth.py
@ -126,6 +126,12 @@ def context_processor(request):
|
|||||||
|
|
||||||
def configure_django():
|
def configure_django():
|
||||||
"""Setup Django configuration in the absense of .settings file"""
|
"""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 = [
|
context_processors = [
|
||||||
'django.contrib.auth.context_processors.auth',
|
'django.contrib.auth.context_processors.auth',
|
||||||
'django.core.context_processors.debug',
|
'django.core.context_processors.debug',
|
||||||
@ -179,9 +185,9 @@ def configure_django():
|
|||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
'django.contrib.messages'],
|
'django.contrib.messages'],
|
||||||
LOGGING=logging_configuration,
|
LOGGING=logging_configuration,
|
||||||
LOGIN_URL=cfg.server_dir + '/accounts/login/',
|
LOGIN_URL='lib:login',
|
||||||
LOGIN_REDIRECT_URL=cfg.server_dir + '/',
|
LOGIN_REDIRECT_URL='apps:index',
|
||||||
LOGOUT_URL=cfg.server_dir + '/accounts/logout/',
|
LOGOUT_URL='lib:logout',
|
||||||
MIDDLEWARE_CLASSES = (
|
MIDDLEWARE_CLASSES = (
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
|
|||||||
11
util.py
11
util.py
@ -1,17 +1,6 @@
|
|||||||
import os
|
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):
|
def mkdir(newdir):
|
||||||
"""works the way a good mkdir should :)
|
"""works the way a good mkdir should :)
|
||||||
- already exists, silently complete
|
- already exists, silently complete
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user