mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #7372: Link to local docs for model from object add/edit views
This commit is contained in:
@@ -7,12 +7,12 @@
|
||||
{% endblock title %}
|
||||
|
||||
{% block controls %}
|
||||
{% if settings.DOCS_ROOT %}
|
||||
{% if obj and settings.DOCS_ROOT %}
|
||||
<div class="controls">
|
||||
<div class="control-group">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#docs_modal" title="Help">
|
||||
<a href="{{ obj|get_docs_url }}" target="_blank" class="btn btn-sm btn-outline-secondary" title="View model documentation">
|
||||
<i class="mdi mdi-help-circle"></i> Help
|
||||
</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -84,7 +84,6 @@
|
||||
<div class="text-end my-3">
|
||||
{% block buttons %}
|
||||
<a class="btn btn-outline-danger" href="{{ return_url }}">Cancel</a>
|
||||
|
||||
{% if obj.pk %}
|
||||
<button type="submit" name="_update" class="btn btn-primary">
|
||||
Save
|
||||
@@ -97,15 +96,10 @@
|
||||
Create
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
{% endblock buttons %}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if obj and settings.DOCS_ROOT %}
|
||||
{% include 'inc/modal.html' with name='docs' content=obj|get_docs %}
|
||||
{% endif %}
|
||||
|
||||
{% endblock content-wrapper %}
|
||||
|
@@ -1,15 +0,0 @@
|
||||
<div class="modal fade" id="{{ name }}_modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
{% if title %}
|
||||
<h5 class="modal-title">{{ title }}</h5>
|
||||
{% endif %}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
{{ content }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@@ -216,27 +216,11 @@ def percentage(x, y):
|
||||
|
||||
|
||||
@register.filter()
|
||||
def get_docs(model):
|
||||
def get_docs_url(model):
|
||||
"""
|
||||
Render and return documentation for the specified model.
|
||||
Return the documentation URL for the specified model.
|
||||
"""
|
||||
path = '{}/models/{}/{}.md'.format(
|
||||
settings.DOCS_ROOT,
|
||||
model._meta.app_label,
|
||||
model._meta.model_name
|
||||
)
|
||||
try:
|
||||
with open(path, encoding='utf-8') as docfile:
|
||||
content = docfile.read()
|
||||
except FileNotFoundError:
|
||||
return "Unable to load documentation, file not found: {}".format(path)
|
||||
except IOError:
|
||||
return "Unable to load documentation, error reading file: {}".format(path)
|
||||
|
||||
# Render Markdown with the admonition extension
|
||||
content = markdown(content, extensions=['admonition', 'fenced_code', 'tables'])
|
||||
|
||||
return mark_safe(content)
|
||||
return f'{settings.STATIC_URL}docs/models/{model._meta.app_label}/{model._meta.model_name}/'
|
||||
|
||||
|
||||
@register.filter()
|
||||
|
Reference in New Issue
Block a user