Skip to content

Commit 3ec0fe5

Browse files
committed
Closes #7372: Link to local docs for model from object add/edit views
1 parent 71449b3 commit 3ec0fe5

File tree

4 files changed

+7
-43
lines changed

4 files changed

+7
-43
lines changed

docs/release-notes/version-3.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* [#6917](https://github.com/netbox-community/netbox/issues/6917) - Make ip assigned checkmark in ip table link to interface
88
* [#7118](https://github.com/netbox-community/netbox/issues/7118) - Render URL custom fields as hyperlinks in object tables
99
* [#7323](https://github.com/netbox-community/netbox/issues/7323) - Add serial filter field for racks & devices
10+
* [#7372](https://github.com/netbox-community/netbox/issues/7372) - Link to local docs for model from object add/edit views
1011

1112
### Bug Fixes
1213

netbox/templates/generic/object_edit.html

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
{% endblock title %}
88

99
{% block controls %}
10-
{% if settings.DOCS_ROOT %}
10+
{% if obj and settings.DOCS_ROOT %}
1111
<div class="controls">
1212
<div class="control-group">
13-
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#docs_modal" title="Help">
13+
<a href="{{ obj|get_docs_url }}" target="_blank" class="btn btn-sm btn-outline-secondary" title="View model documentation">
1414
<i class="mdi mdi-help-circle"></i> Help
15-
</button>
15+
</a>
1616
</div>
1717
</div>
1818
{% endif %}
@@ -84,7 +84,6 @@ <h5 class="offset-sm-3">Custom Fields</h5>
8484
<div class="text-end my-3">
8585
{% block buttons %}
8686
<a class="btn btn-outline-danger" href="{{ return_url }}">Cancel</a>
87-
8887
{% if obj.pk %}
8988
<button type="submit" name="_update" class="btn btn-primary">
9089
Save
@@ -97,15 +96,10 @@ <h5 class="offset-sm-3">Custom Fields</h5>
9796
Create
9897
</button>
9998
{% endif %}
100-
10199
{% endblock buttons %}
102100
</div>
103101
</form>
104102
</div>
105103
</div>
106104

107-
{% if obj and settings.DOCS_ROOT %}
108-
{% include 'inc/modal.html' with name='docs' content=obj|get_docs %}
109-
{% endif %}
110-
111105
{% endblock content-wrapper %}

netbox/templates/inc/modal.html

Lines changed: 0 additions & 15 deletions
This file was deleted.

netbox/utilities/templatetags/helpers.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -216,27 +216,11 @@ def percentage(x, y):
216216

217217

218218
@register.filter()
219-
def get_docs(model):
219+
def get_docs_url(model):
220220
"""
221-
Render and return documentation for the specified model.
221+
Return the documentation URL for the specified model.
222222
"""
223-
path = '{}/models/{}/{}.md'.format(
224-
settings.DOCS_ROOT,
225-
model._meta.app_label,
226-
model._meta.model_name
227-
)
228-
try:
229-
with open(path, encoding='utf-8') as docfile:
230-
content = docfile.read()
231-
except FileNotFoundError:
232-
return "Unable to load documentation, file not found: {}".format(path)
233-
except IOError:
234-
return "Unable to load documentation, error reading file: {}".format(path)
235-
236-
# Render Markdown with the admonition extension
237-
content = markdown(content, extensions=['admonition', 'fenced_code', 'tables'])
238-
239-
return mark_safe(content)
223+
return f'{settings.STATIC_URL}docs/models/{model._meta.app_label}/{model._meta.model_name}/'
240224

241225

242226
@register.filter()

0 commit comments

Comments
 (0)