Просмотр исходного кода

Closes #7372: Link to local docs for model from object add/edit views

jeremystretch 4 лет назад
Родитель
Сommit
3ec0fe5519

+ 1 - 0
docs/release-notes/version-3.0.md

@@ -7,6 +7,7 @@
 * [#6917](https://github.com/netbox-community/netbox/issues/6917) - Make ip assigned checkmark in ip table link to interface
 * [#7118](https://github.com/netbox-community/netbox/issues/7118) - Render URL custom fields as hyperlinks in object tables
 * [#7323](https://github.com/netbox-community/netbox/issues/7323) - Add serial filter field for racks & devices
+* [#7372](https://github.com/netbox-community/netbox/issues/7372) - Link to local docs for model from object add/edit views
 
 ### Bug Fixes
 

+ 3 - 9
netbox/templates/generic/object_edit.html

@@ -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 %}

+ 0 - 15
netbox/templates/inc/modal.html

@@ -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>

+ 3 - 19
netbox/utilities/templatetags/helpers.py

@@ -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()