Repository: learningequality/kolibri
Issue: Kolibri develop: Disabled plugins are still being considered in redirects

Disabling the Learn plugin doesn't unregister the LearnRedirect hook. Which results in the traceback below. Note that we have a similar plugin with aredirect hook for the same roles, however it's URL is not being returned by the `get_url_by_role()` function in `kolibri.core.views`.

## Errors and logs
```
09-06 22:49:09.662 22461 22592 I python  : INFO     127.0.0.1 - - "GET /" 302 0 "" "Mozilla/5.0 (Linux; Android 12; sdk_gpc_x86_64 Build/SE2B.220326.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/95.0.4638.74 Safari/537.36"
09-06 22:49:09.689 22461 22486 D EGL_emulation: app_time_stats: avg=38.40ms min=10.08ms max=84.93ms count=26
09-06 22:49:09.750 22461 22591 I python  : ERROR    Internal Server Error: /en/
09-06 22:49:09.750 22461 22591 I python  : Traceback (most recent call last):
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/urls/base.py", line 77, in reverse
09-06 22:49:09.750 22461 22591 I python  : KeyError: 'kolibri.plugins.learn'
09-06 22:49:09.750 22461 22591 I python  :
09-06 22:49:09.750 22461 22591 I python  : During handling of the above exception, another exception occurred:
09-06 22:49:09.750 22461 22591 I python  :
09-06 22:49:09.750 22461 22591 I python  : Traceback (most recent call last):
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/core/handlers/exception.py", line 41, in inner
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/core/handlers/base.py", line 187, in _get_response
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/core/handlers/base.py", line 185, in _get_response
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/views/generic/base.py", line 68, in view
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/views/generic/base.py", line 88, in dispatch
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/core/views.py", line 158, in get
09-06 22:49:09.751 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/core/views.py", line 103, in get_url_by_role
09-06 22:49:09.751 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/core/views.py", line 107, in <genexpr>
09-06 22:49:09.751 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/plugins/learn/kolibri_plugin.py", line 46, in url
09-06 22:49:09.751 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/core/hooks.py", line 45, in plugin_url
09-06 22:49:09.751 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/plugins/utils/__init__.py", line 54, in plugin_url
09-06 22:49:09.752 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/urls/base.py", line 82, in reverse
09-06 22:49:09.752 22461 22591 I python  : django.urls.exceptions.NoReverseMatch: 'kolibri.plugins.learn' is not a registered namespace inside 'kolibri'
09-06 22:49:09.775 22461 22591 I python  : INFO     127.0.0.1 - - "GET /en/" 500 0 "" "Mozilla/5.0 (Linux; Android 12; sdk_gpc_x86_64 Build/SE2B.220326.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/95.0.4638.74 Safari/537.36"
```


Changed files:
kolibri/plugins/utils/__init__.py, kolibri/utils/cli.py

diff --git a/kolibri/plugins/utils/__init__.py b/kolibri/plugins/utils/__init__.py
index 218401595b..6d72c52048 100644
--- a/kolibri/plugins/utils/__init__.py
+++ b/kolibri/plugins/utils/__init__.py
@@ -89,7 +89,7 @@ def _import_python_module(plugin_name):
             raise
 
 
-def initialize_plugins_and_hooks(all_classes, plugin_name):
+def initialize_plugins_and_hooks(all_classes, plugin_name, initialize_hooks=True):
     was_configured = django_settings.configured
     plugin_objects = []
     for class_definition in all_classes:
@@ -102,7 +102,7 @@ def initialize_plugins_and_hooks(all_classes, plugin_name):
                         class_definition.__name__, plugin_name
                     )
                 )
-        elif issubclass(class_definition, KolibriHook):
+        elif issubclass(class_definition, KolibriHook) and initialize_hooks:
             class_definition.add_hook_to_registries()
             if not was_configured and django_settings.configured:
                 raise PluginLoadsApp(
@@ -125,12 +125,15 @@ def initialize_plugins_and_hooks(all_classes, plugin_name):
         raise MultiplePlugins("More than one plugin defined in kolibri_plugin module")
 
 
-def initialize_kolibri_plugin(plugin_name):
+def initialize_kolibri_plugin(plugin_name, initialize_hooks=True):
     """
     Try to load kolibri_plugin from given plugin module identifier
     In so doing, it will instantiate the KolibriPlugin object if it
     exists, and also register any hooks found in the module.
 
+    Set the initialize_hooks argument to False to just retrieve the kolibri plugin without registering
+    its hooks.
+
     :returns: the KolibriPlugin object for the module
     """
     was_configured = django_settings.configured
@@ -170,7 +173,9 @@ def initialize_kolibri_plugin(plugin_name):
             for cls in plugin_module.__dict__.values()
             if is_plugin_module(cls) and isinstance(cls, type)
         ]
-        return initialize_plugins_and_hooks(all_classes, plugin_name)
+        return initialize_plugins_and_hooks(
+            all_classes, plugin_name, initialize_hooks=initialize_hooks
+        )
 
     except ImportError as e:
         # Python 2: message, Python 3: msg
@@ -190,9 +195,9 @@ def initialize_kolibri_plugin(plugin_name):
         raise PluginLoadsApp(msg)
 
 
-def enable_plugin(plugin_name):
+def enable_plugin(plugin_name, initialize_hooks=False):
     try:
-        obj = initialize_kolibri_plugin(plugin_name)
+        obj = initialize_kolibri_plugin(plugin_name, initialize_hooks=initialize_hooks)
         if obj:
             obj.enable()
             return True
@@ -200,9 +205,9 @@ def enable_plugin(plugin_name):
         logger.error(str(e))
 
 
-def disable_plugin(plugin_name):
+def disable_plugin(plugin_name, initialize_hooks=False):
     try:
-        obj = initialize_kolibri_plugin(plugin_name)
+        obj = initialize_kolibri_plugin(plugin_name, initialize_hooks=initialize_hooks)
         if obj:
             obj.disable()
             return True
diff --git a/kolibri/utils/cli.py b/kolibri/utils/cli.py
index bb407ef00d..4ee533c8e5 100644
--- a/kolibri/utils/cli.py
+++ b/kolibri/utils/cli.py
@@ -394,7 +394,7 @@ def enable(plugin_names, default_plugins):
     for name in plugin_names:
         try:
             logger.info("Enabling plugin '{}'".format(name))
-            error = error or not enable_plugin(name)
+            error = error or not enable_plugin(name, initialize_hooks=True)
         except Exception as e:
             error = True
             logger.error("Error enabling plugin '{}', error was: {}".format(name, e))