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

Closes #6149: Support image attachments for locations

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

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

@@ -11,6 +11,7 @@
 * [#6121](https://github.com/netbox-community/netbox/issues/6121) - Extend parent interface assignment to VM interfaces
 * [#6125](https://github.com/netbox-community/netbox/issues/6125) - Add locations count to home page
 * [#6146](https://github.com/netbox-community/netbox/issues/6146) - Add bulk disconnect support for power feeds
+* [#6149](https://github.com/netbox-community/netbox/issues/6149) - Support image attachments for locations
 * [#6150](https://github.com/netbox-community/netbox/issues/6150) - Enable change logging for journal entries
 
 ### Bug Fixes (from Beta)

+ 3 - 0
netbox/dcim/models/sites.py

@@ -314,6 +314,9 @@ class Location(NestedGroupModel):
         max_length=200,
         blank=True
     )
+    images = GenericRelation(
+        to='extras.ImageAttachment'
+    )
 
     csv_headers = ['site', 'parent', 'name', 'slug', 'description']
     clone_fields = ['site', 'parent', 'description']

+ 1 - 0
netbox/dcim/urls.py

@@ -55,6 +55,7 @@ urlpatterns = [
     path('locations/<int:pk>/edit/', views.LocationEditView.as_view(), name='location_edit'),
     path('locations/<int:pk>/delete/', views.LocationDeleteView.as_view(), name='location_delete'),
     path('locations/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='location_changelog', kwargs={'model': Location}),
+    path('locations/<int:object_id>/images/add/', ImageAttachmentEditView.as_view(), name='location_add_image', kwargs={'model': Location}),
 
     # Rack roles
     path('rack-roles/', views.RackRoleListView.as_view(), name='rackrole_list'),

+ 14 - 0
netbox/templates/dcim/location.html

@@ -58,6 +58,20 @@
   </div>
 	<div class="col-md-6">
     {% include 'inc/custom_fields_panel.html' %}
+    <div class="panel panel-default">
+        <div class="panel-heading">
+            <strong>Images</strong>
+        </div>
+        {% include 'inc/image_attachments.html' with images=object.images.all %}
+        {% if perms.extras.add_imageattachment %}
+            <div class="panel-footer text-right noprint">
+                <a href="{% url 'dcim:location_add_image' object_id=object.pk %}" class="btn btn-primary btn-xs">
+                    <span class="mdi mdi-plus-thick" aria-hidden="true"></span>
+                    Attach an image
+                </a>
+            </div>
+        {% endif %}
+    </div>
     {% plugin_right_page object %}
 	</div>
 </div>