Commit e8f3a873ca7e70fd09b9ccf1bd52328304ab462b
Exists in
master
and in
4 other branches
Merge pull request #100 from colab/removing_namespace
Removing namespace
Showing
4 changed files
with
36 additions
and
4 deletions
Show diff stats
colab/plugins/utils/apps.py
| 1 | 1 | |
| 2 | 2 | from django.apps import AppConfig |
| 3 | +from ..conf import get_plugin_config | |
| 3 | 4 | |
| 4 | 5 | |
| 5 | 6 | class ColabPluginAppConfig(AppConfig): |
| 6 | 7 | colab_proxied_app = True |
| 8 | + namespace = None | |
| 9 | + | |
| 10 | + def __init__(self, app_name, app_module): | |
| 11 | + super(ColabPluginAppConfig, self).__init__(app_name, app_module) | |
| 12 | + self.set_namespace() | |
| 13 | + | |
| 14 | + def set_namespace(self): | |
| 15 | + config = get_plugin_config(self.name) | |
| 16 | + config['urls']['namespace'] = self.namespace | |
| 7 | 17 | |
| 8 | 18 | def register_signal(self): |
| 9 | 19 | pass | ... | ... |
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +from mock import patch | |
| 2 | + | |
| 3 | +from django.test import TestCase | |
| 4 | +from django.apps import AppConfig | |
| 5 | + | |
| 6 | +from colab.plugins.utils.apps import ColabPluginAppConfig | |
| 7 | + | |
| 8 | + | |
| 9 | +class AppsTest(TestCase): | |
| 10 | + | |
| 11 | + @patch.object(AppConfig, '_path_from_module') | |
| 12 | + @patch('colab.plugins.utils.apps.get_plugin_config') | |
| 13 | + def test_set_namespace(self, get_plugin_config_mock, | |
| 14 | + path_from_module_mock): | |
| 15 | + path_from_module_mock.return_value = "/fake/path" | |
| 16 | + | |
| 17 | + get_plugin_config_mock.return_value = {'urls': {}} | |
| 18 | + conf = get_plugin_config_mock() | |
| 19 | + | |
| 20 | + ColabPluginAppConfig("test", "test_app") | |
| 21 | + | |
| 22 | + self.assertIn('namespace', conf['urls']) | |
| 23 | + self.assertEquals(None, conf['urls']['namespace']) | ... | ... |
docs/source/plugindev.rst
| ... | ... | @@ -23,6 +23,8 @@ signals structure, some steps are required: |
| 23 | 23 | contain any special character, such as dot or comma. It is suggested to name |
| 24 | 24 | the variable "short_name", but that nomenclature is not strictly |
| 25 | 25 | necessary. |
| 26 | +* Finally, the variable namespace should also be defined. This variable is the | |
| 27 | + url namespace for django reverse. | |
| 26 | 28 | * In order to actually register the signals, it is necessary to implement the |
| 27 | 29 | method register_signal, which require the name of the plugin that is |
| 28 | 30 | registering the signals and a list of signals to be registered as parameters. |
| ... | ... | @@ -57,6 +59,7 @@ signals structure, some steps are required: |
| 57 | 59 | class PluginApps(ColabPluginAppConfig): |
| 58 | 60 | short_name = PLUGIN_NAME |
| 59 | 61 | signals_list = [SIGNAL1, SIGNAL2] |
| 62 | + namespace = PLUGIN_NAMESPACE | |
| 60 | 63 | |
| 61 | 64 | def registered_signal(self): |
| 62 | 65 | register_signal(self.short_name, self.signals_list) | ... | ... |
docs/source/user.rst
| ... | ... | @@ -118,7 +118,6 @@ Use this template for the plugin configuration file |
| 118 | 118 | |
| 119 | 119 | urls = { |
| 120 | 120 | 'include': '[plugin_module_path].urls', |
| 121 | - 'namespace': '[plugin_name]', | |
| 122 | 121 | 'prefix': '[application_prefix]/', # Exemple: http://site.com/[application_prefix]/ |
| 123 | 122 | } |
| 124 | 123 | |
| ... | ... | @@ -177,9 +176,6 @@ urls |
| 177 | 176 | Declares the prefix for the url. |
| 178 | 177 | |
| 179 | 178 | - Atention: Any URL used in the plugins' settings should not be preceded by "/" |
| 180 | -.. attribute:: namespace | |
| 181 | - | |
| 182 | - Declares the namespace for the url. | |
| 183 | 179 | |
| 184 | 180 | menu |
| 185 | 181 | ++++ | ... | ... |