From dbe66596f90803034b5dd1eb1d4a0e070f584c36 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 27 Oct 2022 09:44:09 -0400 Subject: [PATCH] Closes #9887: Inspect docs_url property to determine link to model documentation --- docs/plugins/development/models.md | 6 ++++++ docs/release-notes/version-3.4.md | 1 + netbox/netbox/models/__init__.py | 5 +++++ netbox/templates/generic/object_edit.html | 4 ++-- netbox/utilities/templatetags/helpers.py | 8 -------- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/plugins/development/models.md b/docs/plugins/development/models.md index 16f5dd0df..b3bcb292a 100644 --- a/docs/plugins/development/models.md +++ b/docs/plugins/development/models.md @@ -49,6 +49,12 @@ class MyModel(NetBoxModel): ... ``` +### NetBoxModel Properties + +#### `docs_url` + +This attribute specifies the URL at which the documentation for this model can be reached. By default, it will return `/static/docs/models///`. Plugin models can override this to return a custom URL. For example, you might direct the user to your plugin's documentation hosted on [ReadTheDocs](https://readthedocs.org/). + ### Enabling Features Individually If you prefer instead to enable only a subset of these features for a plugin model, NetBox provides a discrete "mix-in" class for each feature. You can subclass each of these individually when defining your model. (Your model will also need to inherit from Django's built-in `Model` class.) diff --git a/docs/release-notes/version-3.4.md b/docs/release-notes/version-3.4.md index 93e2c8841..eefb0ee21 100644 --- a/docs/release-notes/version-3.4.md +++ b/docs/release-notes/version-3.4.md @@ -40,6 +40,7 @@ A new `PluginMenu` class has been introduced, which enables a plugin to inject a * [#9071](https://github.com/netbox-community/netbox/issues/9071) - Introduce `PluginMenu` for top-level plugin navigation menus * [#9072](https://github.com/netbox-community/netbox/issues/9072) - Enable registration of tabbed plugin views for core NetBox models * [#9880](https://github.com/netbox-community/netbox/issues/9880) - Introduce `django_apps` plugin configuration parameter +* [#9887](https://github.com/netbox-community/netbox/issues/9887) - Inspect `docs_url` property to determine link to model documentation * [#10314](https://github.com/netbox-community/netbox/issues/10314) - Move `clone()` method from NetBoxModel to CloningMixin * [#10739](https://github.com/netbox-community/netbox/issues/10739) - Introduce `get_queryset()` method on generic views diff --git a/netbox/netbox/models/__init__.py b/netbox/netbox/models/__init__.py index 1385dd585..2f2dc1c9f 100644 --- a/netbox/netbox/models/__init__.py +++ b/netbox/netbox/models/__init__.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.core.validators import ValidationError from django.db import models from mptt.models import MPTTModel, TreeForeignKey @@ -26,6 +27,10 @@ class NetBoxFeatureSet( class Meta: abstract = True + @property + def docs_url(self): + return f'{settings.STATIC_URL}docs/models/{self._meta.app_label}/{self._meta.model_name}/' + @classmethod def get_prerequisite_models(cls): """ diff --git a/netbox/templates/generic/object_edit.html b/netbox/templates/generic/object_edit.html index 56e4f5a32..c61fb723f 100644 --- a/netbox/templates/generic/object_edit.html +++ b/netbox/templates/generic/object_edit.html @@ -37,9 +37,9 @@ Context: {% endif %} {# Link to model documentation #} - {% if object and settings.DOCS_ROOT %} + {% if settings.DOCS_ROOT and object.docs_url %} diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 462b37feb..9789724ee 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -141,14 +141,6 @@ def percentage(x, y): return round(x / y * 100) -@register.filter() -def get_docs_url(model): - """ - Return the documentation URL for the specified model. - """ - return f'{settings.STATIC_URL}docs/models/{model._meta.app_label}/{model._meta.model_name}/' - - @register.filter() def has_perms(user, permissions_list): """