refactor help icon code to support plugins #4462

Closed
opened 2025-12-29 18:36:14 +01:00 by adam · 1 comment
Owner

Originally created by @pvinci on GitHub (Jan 14, 2021).

Environment

  • Python version: 3.8
  • NetBox version: Develop

Proposed Functionality

Today, get_docs in helper.py, gets the location of the document to display from settings.DOCS_ROOT, which is outside of the scope of a plugin.

I propose that for a plugin we specify a path within the plugin's space.
We could add a docs_root to PluginConfig and reference it instead.

As a simple proof of concept, it is already possible to add a new path to each model with minimal changes which could be encapsulated into a mixin:

    here = os.path.abspath(os.path.dirname(__file__))
    def __init__(self, *args, **kwargs):
        super(MyPluginModel, self).__init__(*args, **kwargs)
        self._meta.DOCS_ROOT = "%s/docs" % here
+++ b/netbox/utilities/templatetags/helpers.py
@@ -173,8 +173,12 @@ def get_docs(model):
     """
     Render and return documentation for the specified model.
     """
+    try:
+        docs_root = model._meta.DOCS_ROOT
+    except AttributeError:
+        docs_root = settings.DOCS_ROOT
     path = '{}/models/{}/{}.md'.format(
-        settings.DOCS_ROOT,
+        docs_root,
         model._meta.app_label,
         model._meta.model_name
     )

Use Case

Allow a plugin to bundle its own model help. Currently, it is configured to display a url it cannot install into.

Database Changes

None

External Dependencies

None

Originally created by @pvinci on GitHub (Jan 14, 2021). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for proposing specific new features or enhancements. If you have a general idea or question, please start a discussion instead: https://github.com/netbox-community/netbox/discussions NOTE: Due to an excessive backlog of feature requests, we are not currently accepting any proposals which significantly extend NetBox's feature scope. Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.8 * NetBox version: Develop <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality Today, [get_docs](https://github.com/netbox-community/netbox/blob/develop/netbox/utilities/templatetags/helpers.py#L172) in helper.py, gets the location of the document to display from settings.DOCS_ROOT, which is outside of the scope of a plugin. I propose that for a plugin we specify a path within the plugin's space. We could add a docs_root to PluginConfig and reference it instead. As a simple proof of concept, it is already possible to add a new path to each model with minimal changes which could be encapsulated into a mixin: ``` here = os.path.abspath(os.path.dirname(__file__)) def __init__(self, *args, **kwargs): super(MyPluginModel, self).__init__(*args, **kwargs) self._meta.DOCS_ROOT = "%s/docs" % here ``` ``` +++ b/netbox/utilities/templatetags/helpers.py @@ -173,8 +173,12 @@ def get_docs(model): """ Render and return documentation for the specified model. """ + try: + docs_root = model._meta.DOCS_ROOT + except AttributeError: + docs_root = settings.DOCS_ROOT path = '{}/models/{}/{}.md'.format( - settings.DOCS_ROOT, + docs_root, model._meta.app_label, model._meta.model_name ) ``` <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case Allow a plugin to bundle its own model help. Currently, it is configured to display a url it cannot install into. <!-- Note any changes to the database schema necessary to support the new feature. For example, does the proposal require adding a new model or field? (Not all new features require database changes.) ---> ### Database Changes None <!-- List any new dependencies on external libraries or services that this new feature would introduce. For example, does the proposal require the installation of a new Python package? (Not all new features introduce new dependencies.) --> ### External Dependencies None
adam closed this issue 2025-12-29 18:36:14 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 14, 2021):

This helper function is not supported for use by plugins. Plugin authors can create their own documentation links within the plugin's templates.

@jeremystretch commented on GitHub (Jan 14, 2021): This helper function is not supported for use by plugins. Plugin authors can create their own documentation links within the plugin's templates.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4462