netbox-device-view 0.1.7__py3-none-any.whl → 0.1.10a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,23 @@
1
- from netbox.forms import NetBoxModelForm
1
+ from netbox.forms import NetBoxModelForm, NetBoxModelImportForm
2
+ from django.utils.translation import gettext_lazy as _
2
3
  from .models import DeviceView
4
+ from dcim.models import DeviceType
5
+ from utilities.forms.fields import CSVModelChoiceField
3
6
 
4
7
 
5
8
  class DeviceViewForm(NetBoxModelForm):
6
9
  class Meta:
7
10
  model = DeviceView
8
11
  fields = ("device_type", "grid_template_area")
12
+
13
+
14
+ class DeviceViewImportForm(NetBoxModelImportForm):
15
+ device_type = CSVModelChoiceField(
16
+ queryset=DeviceType.objects.all(),
17
+ to_field_name="model",
18
+ help_text=_("Device Model Name"),
19
+ )
20
+
21
+ class Meta:
22
+ model = DeviceView
23
+ fields = ("device_type", "grid_template_area")
@@ -7,7 +7,12 @@ deviceview_buttons = [
7
7
  title="Add",
8
8
  icon_class="mdi mdi-plus-thick",
9
9
  color=ButtonColorChoices.GREEN,
10
- )
10
+ ),
11
+ PluginMenuButton(
12
+ link="plugins:netbox_device_view:deviceview_import",
13
+ title="Import",
14
+ icon_class="mdi mdi-upload",
15
+ ),
11
16
  ]
12
17
 
13
18
  menu_items = (
@@ -60,11 +60,7 @@
60
60
  {% endfor %}
61
61
  {% endif %}
62
62
  "
63
- style="grid-area: {{ int.stylename }};
64
- {% if cable_colors == "on" and int.cable.color != "" %}
65
- background-color: #{{ int.cable.color }}
66
- {% endif %}
67
- "
63
+ style="grid-area: {{ int.stylename }}{% if cable_colors == 'on' and int.cable.color != '' %}; background-color: #{{ int.cable.color }}{% endif %}"
68
64
  data-bs-toggle="tooltip"
69
65
  data-bs-html="true"
70
66
  data-bs-custom-class="device-view-tooltip"
@@ -5,6 +5,11 @@ from netbox.views.generic import ObjectChangeLogView
5
5
  urlpatterns = (
6
6
  path("device-view/", views.DeviceViewListView.as_view(), name="deviceview_list"),
7
7
  path("device-view/add/", views.DeviceViewEditView.as_view(), name="deviceview_add"),
8
+ path(
9
+ "device-view/import/",
10
+ views.DeviceViewBulkImportView.as_view(),
11
+ name="deviceview_import",
12
+ ),
8
13
  path("device-view/<int:pk>/", views.DeviceViewView.as_view(), name="deviceview"),
9
14
  path(
10
15
  "device-view/<int:pk>/edit/",
@@ -10,19 +10,27 @@ def process_interfaces(interfaces, ports_chassis, dev):
10
10
  for itf in interfaces:
11
11
  if itf.type == "virtual" or itf.type == "lag":
12
12
  continue
13
- regex = r"^(?P<type>([a-zA-Z\-_]*))(\/|(?P<dev>[0-9]+).|\s)?((?P<module>[0-9]+).|\s)?((?P<port>[0-9]+))$"
14
- matches = re.search(regex, itf.name.lower())
15
- if matches:
16
- itf.stylename = (
17
- (matches["type"] or "")
18
- + (matches["module"] or "")
19
- + "-"
20
- + matches["port"]
21
- )
22
- else:
23
- itf.stylename = re.sub(r"[^.a-zA-Z\d]", "-", itf.name.lower())
24
- if itf.stylename.isdigit():
13
+ # Convert to lowercase and replace common separators with hyphens
14
+ # This replaces the original regex matching and if/else block
15
+ stylename = re.sub(r"[/\.\s]+", "-", itf.name.lower())
16
+
17
+ # Clean up multiple hyphens and leading/trailing hyphens
18
+ stylename = re.sub(r"-+", "-", stylename).strip("-")
19
+
20
+ # If the name becomes empty after cleaning, use a fallback
21
+ if not stylename:
22
+ stylename = f"iface-{itf.pk}" # Use a unique fallback
23
+
24
+ # Assign the generated stylename back to the object property
25
+ itf.stylename = stylename
26
+
27
+ # Check if the stylename exists and starts with a digit or a hyphen
28
+ # This replaces the original 'if itf.stylename.isdigit():' line
29
+ if itf.stylename and (
30
+ itf.stylename[0].isdigit() or itf.stylename[0] == "-"
31
+ ):
25
32
  itf.stylename = f"p{itf.stylename}"
33
+
26
34
  if dev not in ports_chassis:
27
35
  ports_chassis[dev] = []
28
36
  ports_chassis[dev].append(itf)
@@ -55,13 +63,15 @@ def prepare(obj):
55
63
  device_type=obj.device_type
56
64
  ).grid_template_area
57
65
  modules[1] = obj.modules.all()
58
- ports_chassis = process_interfaces(obj.interfaces.all(), ports_chassis, 1)
66
+ ports_chassis = process_interfaces(
67
+ obj.interfaces.all(), ports_chassis, obj.name
68
+ )
59
69
  ports_chassis = process_ports(obj.frontports.all(), ports_chassis, "Front")
60
70
  ports_chassis = process_ports(obj.rearports.all(), ports_chassis, "Rear")
61
71
  ports_chassis = process_ports(
62
72
  ConsolePort.objects.filter(device_id=obj.id),
63
73
  ports_chassis,
64
- list(ports_chassis.keys())[0],
74
+ obj.name,
65
75
  )
66
76
  else:
67
77
  for member in obj.virtual_chassis.members.all():
@@ -6,6 +6,9 @@ from .utils import prepare
6
6
  from django.http import HttpResponse
7
7
  import pprint
8
8
 
9
+ from netbox.views.generic import BulkImportView
10
+ from netbox_device_view.forms import DeviceViewImportForm
11
+
9
12
 
10
13
  class DeviceViewView(generic.ObjectView):
11
14
  queryset = models.DeviceView.objects
@@ -21,6 +24,11 @@ class DeviceViewEditView(generic.ObjectEditView):
21
24
  form = forms.DeviceViewForm
22
25
 
23
26
 
27
+ class DeviceViewBulkImportView(BulkImportView):
28
+ queryset = models.DeviceView.objects.all()
29
+ model_form = DeviceViewImportForm
30
+
31
+
24
32
  class DeviceViewDeleteView(generic.ObjectDeleteView):
25
33
  queryset = models.DeviceView.objects
26
34
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: netbox-device-view
3
- Version: 0.1.7
3
+ Version: 0.1.10a0
4
4
  Summary: NetBox Device View plugin
5
5
  Home-page: https://github.com/peterbaumert/netbox-device-view
6
6
  Author: Peter Baumert
@@ -8,6 +8,13 @@ Keywords: netbox,netbox-plugin
8
8
  Classifier: Framework :: Django
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Description-Content-Type: text/markdown
11
+ Dynamic: author
12
+ Dynamic: classifier
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: home-page
16
+ Dynamic: keywords
17
+ Dynamic: summary
11
18
 
12
19
  # Netbox Device View Plugin
13
20
  ![Version](https://img.shields.io/pypi/v/netbox-device-view) ![Downloads](https://img.shields.io/pypi/dm/netbox-device-view)
@@ -1,13 +1,13 @@
1
1
  netbox_device_view/__init__.py,sha256=UEs107Oqb9efDbmxnfheCTQFuaukXQgICuwW3qtJi08,532
2
2
  netbox_device_view/filtersets.py,sha256=kCPEIzue5bOeyFK_Aqhpi1VQ_YQvqyDBd4dvP2UqVAU,215
3
- netbox_device_view/forms.py,sha256=rr9gVDDbP_DSQP0oOTVPWjd4Mti87tcOLDf742-y6qQ,211
3
+ netbox_device_view/forms.py,sha256=JABwFhv4zU08vSaO2C8rSdnbfuNGpeHGtGnLlY2X2wU,692
4
4
  netbox_device_view/models.py,sha256=MN6eThuBJ1bm-vsQF1zM6He5cgKpMfZeCBqHmAjuHTA,500
5
- netbox_device_view/navigation.py,sha256=VU3N-Z9xIgxtlkvcdPJym8R4rDtcJBr_Axjlk39V_os,494
5
+ netbox_device_view/navigation.py,sha256=EbmAxA0a8y47jbf8XjRQvz_xAvoTwTHI9ljvC6oaX9U,646
6
6
  netbox_device_view/tables.py,sha256=ejhKjD5fGo_tLUhTExqBhDL_TbYVe9TPnzF-ZWHqujY,351
7
7
  netbox_device_view/template_content.py,sha256=4B_aiNS6ARoAv97-I6M1-2fCSIc3UcBW0tuRhy0sDZU,1072
8
- netbox_device_view/urls.py,sha256=UhLOmfj0v4ofRnHM-bxisTnIPQ2viS8I47AyHiA20LU,839
9
- netbox_device_view/utils.py,sha256=uUPJnwYfEpM6H61Z-BkyNeQwmWm3xJY5Z9-Xe9Jp7f8,3191
10
- netbox_device_view/views.py,sha256=8OQQE-BZPM_ZXXopiRGJStdXq6eAE_tndfRVvHLkA2U,1778
8
+ netbox_device_view/urls.py,sha256=DtdIPVagp1KHwPDSlBsV_rJ16pGNi8l661RkXTq32HU,971
9
+ netbox_device_view/utils.py,sha256=NPEgzyZwBMyLWf9Km2iMwJt0eOOIzUiLXRCGMw299Mc,3580
10
+ netbox_device_view/views.py,sha256=hyz6xOt0l3l2Kh0cf-TTG84JfF810ts9_SL3SsRpbGM,2020
11
11
  netbox_device_view/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  netbox_device_view/api/serializers.py,sha256=IQEFuIh7X22MWO4jxv4MctZQxln-DgH2eo-0IbdvBl4,456
13
13
  netbox_device_view/api/urls.py,sha256=cHDu5GtasFztt4zt-rj-Qkjkul8_lJ4-pxHmJ8GfDvk,205
@@ -15,9 +15,9 @@ netbox_device_view/api/views.py,sha256=4sID0Rad-OVBnTD4MTpMpMYg-FnOLQlsyIhfcNsg2
15
15
  netbox_device_view/migrations/0001_initial.py,sha256=2maF1lEro3LuqdQqKwrBs1ABpw7KsTdTqLxiSlrU_SI,1783
16
16
  netbox_device_view/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  netbox_device_view/static/netbox_device_view/css/device_view.css,sha256=VnvjTMPrEnUkpb_odDe6-VJKhBXZ6RuII4Ce3EnPDCc,833
18
- netbox_device_view/templates/netbox_device_view/deviceview.html,sha256=iYfqjTO_tvp0c7_0s7AxKmzHC_6JRxxbRahPxoTi3NQ,2893
18
+ netbox_device_view/templates/netbox_device_view/deviceview.html,sha256=gnHwrEhsIHQ5Mv8KjIgUVa65rmfMy7_hLx-wgjHV6-c,2874
19
19
  netbox_device_view/templates/netbox_device_view/ports.html,sha256=H-OVDZfpa-s3NB5a3ZJmrNbir001wfYfKJss8bppBgk,1716
20
- netbox_device_view-0.1.7.dist-info/METADATA,sha256=LkaZ65ldo2ebstj8kJ2qKIfCk-ELTkZqFl_20fUBf_c,3753
21
- netbox_device_view-0.1.7.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
22
- netbox_device_view-0.1.7.dist-info/top_level.txt,sha256=Cj7X6_XpLT0jnyTyX5DMqttqc8_z3uhRYCmvnXLfWOs,19
23
- netbox_device_view-0.1.7.dist-info/RECORD,,
20
+ netbox_device_view-0.1.10a0.dist-info/METADATA,sha256=NCvezhy__GrfdRnDO8l4AurMg_cWPfo7wKVfuw8vnp0,3901
21
+ netbox_device_view-0.1.10a0.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
22
+ netbox_device_view-0.1.10a0.dist-info/top_level.txt,sha256=Cj7X6_XpLT0jnyTyX5DMqttqc8_z3uhRYCmvnXLfWOs,19
23
+ netbox_device_view-0.1.10a0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.0.0)
2
+ Generator: setuptools (80.3.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5