From a82a83576f8ad2c88a6f56f9b593c03c160b8e64 Mon Sep 17 00:00:00 2001 From: fonfon Date: Thu, 10 Jul 2014 03:44:52 +0000 Subject: [PATCH] use djangos named URLs and url-reverse instead of manually constructing urls --- menu.py | 3 +-- module_loader.py | 6 +++--- modules/apps/urls.py | 2 +- modules/config/urls.py | 2 +- modules/diagnostics/templates/diagnostics.html | 6 +++--- modules/diagnostics/urls.py | 4 ++-- modules/expert_mode/urls.py | 2 +- modules/firewall/urls.py | 2 +- modules/first_boot/first_boot.py | 6 +++--- .../first_boot/templates/firstboot_state1.html | 2 +- modules/first_boot/urls.py | 6 +++--- modules/help/help.py | 18 +++++++++++------- modules/help/templates/about.html | 3 ++- modules/help/templates/help.html | 4 ++-- modules/help/urls.py | 15 +++++++-------- modules/lib/urls.py | 5 ++--- modules/owncloud/templates/owncloud.html | 2 +- modules/owncloud/urls.py | 2 +- modules/packages/urls.py | 2 +- .../templates/pagekite_introduction.html | 2 +- modules/pagekite/urls.py | 4 ++-- modules/system/urls.py | 2 +- modules/tor/urls.py | 2 +- modules/users/urls.py | 6 +++--- modules/xmpp/urls.py | 6 +++--- plinth.py | 1 + templates/base.html | 10 +++++----- urls.py | 2 +- util.py | 18 +----------------- views.py | 12 +++++++----- 30 files changed, 73 insertions(+), 84 deletions(-) diff --git a/menu.py b/menu.py index 4522768a3..bcda4fd73 100644 --- a/menu.py +++ b/menu.py @@ -1,4 +1,3 @@ -from urlparse import urlparse import util import cfg @@ -70,7 +69,7 @@ class Menu(object): return request_path.startswith(self.url) def active_item(self, request): - """Return item list (e.g. submenu) of active menu item.""" + """Return the first active item that is found""" for item in self.items: if request.path.startswith(item.url): return item diff --git a/module_loader.py b/module_loader.py index cf990394b..ad5214776 100644 --- a/module_loader.py +++ b/module_loader.py @@ -48,7 +48,7 @@ def load_modules(): LOGGER.exception('Could not import modules/%s: %s', name, exception) - _include_module_urls(full_name) + _include_module_urls(full_name, name) ordered_modules = [] remaining_modules = dict(modules) @@ -97,13 +97,13 @@ def _insert_modules(module_name, module, remaining_modules, ordered_modules): ordered_modules.append(module_name) -def _include_module_urls(module_name): +def _include_module_urls(module_name, namespace): """Include the module's URLs in global project URLs list""" url_module = module_name + '.urls' try: urls.urlpatterns += django.conf.urls.patterns( '', django.conf.urls.url( - r'', django.conf.urls.include(url_module))) + r'', django.conf.urls.include(url_module, namespace))) except ImportError: LOGGER.debug('No URLs for %s', module_name) diff --git a/modules/apps/urls.py b/modules/apps/urls.py index a65383f51..b47f44cde 100644 --- a/modules/apps/urls.py +++ b/modules/apps/urls.py @@ -24,5 +24,5 @@ from django.conf.urls import patterns, url urlpatterns = patterns( # pylint: disable-msg=C0103 'modules.apps.apps', - url(r'^apps/$', 'index') + url(r'^apps/$', 'index', name='index') ) diff --git a/modules/config/urls.py b/modules/config/urls.py index e40bdf15a..e80f518dc 100644 --- a/modules/config/urls.py +++ b/modules/config/urls.py @@ -24,5 +24,5 @@ from django.conf.urls import patterns, url urlpatterns = patterns( # pylint: disable-msg=C0103 'modules.config.config', - url(r'^sys/config/$', 'index'), + url(r'^sys/config/$', 'index', name='index'), ) diff --git a/modules/diagnostics/templates/diagnostics.html b/modules/diagnostics/templates/diagnostics.html index f104ef2f8..c85203f08 100644 --- a/modules/diagnostics/templates/diagnostics.html +++ b/modules/diagnostics/templates/diagnostics.html @@ -24,8 +24,8 @@ system to confirm that network services are running and configured properly. It may take a minute to complete.

-

Run diagnostic test -»

+

+ Run diagnostic test » +

{% endblock %} diff --git a/modules/diagnostics/urls.py b/modules/diagnostics/urls.py index 5b3d94653..4ed974f9b 100644 --- a/modules/diagnostics/urls.py +++ b/modules/diagnostics/urls.py @@ -24,6 +24,6 @@ from django.conf.urls import patterns, url urlpatterns = patterns( # pylint: disable-msg=C0103 'modules.diagnostics.diagnostics', - url(r'^sys/diagnostics/$', 'index'), - url(r'^sys/diagnostics/test/$', 'test'), + url(r'^sys/diagnostics/$', 'index', name='index'), + url(r'^sys/diagnostics/test/$', 'test', name='test'), ) diff --git a/modules/expert_mode/urls.py b/modules/expert_mode/urls.py index 83ed46428..ffb97da53 100644 --- a/modules/expert_mode/urls.py +++ b/modules/expert_mode/urls.py @@ -24,5 +24,5 @@ from django.conf.urls import patterns, url urlpatterns = patterns( # pylint: disable-msg=C0103 'modules.expert_mode.expert_mode', - url(r'^sys/expert/$', 'index'), + url(r'^sys/expert/$', 'index', name='index'), ) diff --git a/modules/firewall/urls.py b/modules/firewall/urls.py index 62ae413e7..be2f1494a 100644 --- a/modules/firewall/urls.py +++ b/modules/firewall/urls.py @@ -24,5 +24,5 @@ from django.conf.urls import patterns, url urlpatterns = patterns( # pylint: disable-msg=C0103 'modules.firewall.firewall', - url(r'^sys/firewall/$', 'index') + url(r'^sys/firewall/$', 'index', name='index') ) diff --git a/modules/first_boot/first_boot.py b/modules/first_boot/first_boot.py index c9ecf5ff9..f784c507b 100644 --- a/modules/first_boot/first_boot.py +++ b/modules/first_boot/first_boot.py @@ -21,6 +21,7 @@ The Plinth first-connection process has several stages: from django import forms from django.contrib import messages from django.core import validators +from django.core.urlresolvers import reverse from django.http.response import HttpResponseRedirect from django.template.response import TemplateResponse from gettext import gettext as _ @@ -94,7 +95,7 @@ def state0(request): """ try: if _read_state() >= 5: - return HttpResponseRedirect(cfg.server_dir) + return HttpResponseRedirect(reverse('index')) except KeyError: pass @@ -112,8 +113,7 @@ def state0(request): if success: # Everything is good, permanently mark and move to page 2 _write_state(1) - return HttpResponseRedirect( - cfg.server_dir + '/firstboot/state1') + return HttpResponseRedirect(reverse('first_boot:state1')) else: form = State0Form(initial=status, prefix='firstboot') diff --git a/modules/first_boot/templates/firstboot_state1.html b/modules/first_boot/templates/firstboot_state1.html index 7a40fcf1e..fdc675f39 100644 --- a/modules/first_boot/templates/firstboot_state1.html +++ b/modules/first_boot/templates/firstboot_state1.html @@ -23,7 +23,7 @@ {% block main_block %}

Welcome screen not completely implemented yet. Press continue to see the rest of the + href="{% url 'apps:index' %}">continue to see the rest of the web interface.