Преглед на файлове

HUE-788 [core] Enable apps to be url namespaced

When we register the URLs of an app with a namespace,
all the reversed views will need to have the namespace of the app.

If the namespace in the url is not specified
(e.g. 'list_dir' instead of 'filebrowser:list_dir') the 'list_dir'
view does not exist for Django as it was registered from urls.py
with the namespace 'filebrowser'. In consequence all the urls of
an app need to be converted with the namespace before switching
'IS_URL_NAMESPACED' to True (or a "Reverse for 'view' with arguments '()'"
will show up.).
Romain Rigaux преди 13 години
родител
ревизия
45ec32f
променени са 2 файла, в които са добавени 7 реда и са изтрити 2 реда
  1. 2 0
      desktop/core/src/desktop/appmanager.py
  2. 5 2
      desktop/core/src/desktop/urls.py

+ 2 - 0
desktop/core/src/desktop/appmanager.py

@@ -126,6 +126,8 @@ class DesktopModuleInfo(object):
     else:
     else:
         self.menu_index = 999
         self.menu_index = 999
 
 
+    self.is_url_namespaced = hasattr(self.settings, 'IS_URL_NAMESPACED')
+
     if self.config_key is not None:
     if self.config_key is not None:
       self.display_name = self.config_key
       self.display_name = self.config_key
 
 

+ 5 - 2
desktop/core/src/desktop/urls.py

@@ -71,8 +71,11 @@ static_patterns = []
 # Root each app at /appname if they have a "urls" module
 # Root each app at /appname if they have a "urls" module
 for app in appmanager.DESKTOP_APPS:
 for app in appmanager.DESKTOP_APPS:
   if app.urls:
   if app.urls:
-    dynamic_patterns.extend( patterns('', ('^' + re.escape(app.name) + '/',
-                                           include(app.urls))) )
+    if app.is_url_namespaced:
+      namespace = {'namespace': app.name, 'app_name': app.name}
+    else:
+      namespace = {}
+    dynamic_patterns.extend( patterns('', ('^' + re.escape(app.name) + '/', include(app.urls, **namespace))) )
     app.urls_imported = True
     app.urls_imported = True
 
 
   # Root a /appname/static if they have a static dir
   # Root a /appname/static if they have a static dir