Skip to content

Various fixes #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0d0e11a
Update deviceview.html to correct malformed int.stylename value in st…
cmcknz77 Apr 11, 2025
27cf9fd
Update utils.py
cmcknz77 Apr 13, 2025
ac94ffd
Merge pull request #1 from cmcknz77/cmcknz77-patch-2
cmcknz77 Apr 13, 2025
4feb808
Merge pull request #2 from cmcknz77/cmcknz77-patch-1
cmcknz77 Apr 13, 2025
0d39f0b
Revert "Update deviceview.html to correct malformed int.stylename val…
cmcknz77 May 1, 2025
b68900d
Merge pull request #3 from cmcknz77/revert-2-cmcknz77-patch-1
cmcknz77 May 1, 2025
e791852
Revert "Update utils.py"
cmcknz77 May 1, 2025
c3288d7
Merge pull request #4 from cmcknz77/revert-1-cmcknz77-patch-2
cmcknz77 May 1, 2025
746314c
1. Problem: Trailing Semicolon and Space in the style Attribute for I…
cmcknz77 May 1, 2025
62eb7d1
2. Problem: Incorrect stylename Generation Logic for Interfaces with …
cmcknz77 May 1, 2025
b702108
3. Problem: Insufficient Validation of Generated stylename as a Valid…
cmcknz77 May 1, 2025
85117d2
Merge pull request #5 from cmcknz77/cmcknz77-patch-3
cmcknz77 May 1, 2025
5494833
Update setup.py
cmcknz77 May 1, 2025
102ee6c
Update setup.py
cmcknz77 May 1, 2025
3bbe708
Correct formatting errors
cmcknz77 May 4, 2025
8a28855
Removed an unecessary comment causing black to fail.
cmcknz77 May 4, 2025
e3ad567
Correct repo url in setup.py
cmcknz77 May 4, 2025
ba2906b
Add cleaning method for grid_template_area to standardize whitespace …
cmcknz77 May 4, 2025
ebe5b34
Revert issue-43 change
cmcknz77 May 4, 2025
99dbf02
format
cmcknz77 May 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@
{% endfor %}
{% endif %}
"
style="grid-area: {{ int.stylename }};
{% if cable_colors == "on" and int.cable.color != "" %}
background-color: #{{ int.cable.color }}
{% endif %}
"
style="grid-area: {{ int.stylename }}{% if cable_colors == 'on' and int.cable.color != '' %}; background-color: #{{ int.cable.color }}{% endif %}"
data-bs-toggle="tooltip"
data-bs-html="true"
data-bs-custom-class="device-view-tooltip"
Expand Down
36 changes: 23 additions & 13 deletions netbox_device_view/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ def process_interfaces(interfaces, ports_chassis, dev):
for itf in interfaces:
if itf.type == "virtual" or itf.type == "lag":
continue
regex = r"^(?P<type>([a-zA-Z\-_]*))(\/|(?P<dev>[0-9]+).|\s)?((?P<module>[0-9]+).|\s)?((?P<port>[0-9]+))$"
matches = re.search(regex, itf.name.lower())
if matches:
itf.stylename = (
(matches["type"] or "")
+ (matches["module"] or "")
+ "-"
+ matches["port"]
)
else:
itf.stylename = re.sub(r"[^.a-zA-Z\d]", "-", itf.name.lower())
if itf.stylename.isdigit():
# Convert to lowercase and replace common separators with hyphens
# This replaces the original regex matching and if/else block
stylename = re.sub(r"[/\.\s]+", "-", itf.name.lower())

# Clean up multiple hyphens and leading/trailing hyphens
stylename = re.sub(r"-+", "-", stylename).strip("-")

# If the name becomes empty after cleaning, use a fallback
if not stylename:
stylename = f"iface-{itf.pk}" # Use a unique fallback

# Assign the generated stylename back to the object property
itf.stylename = stylename

# Check if the stylename exists and starts with a digit or a hyphen
# This replaces the original 'if itf.stylename.isdigit():' line
if itf.stylename and (
itf.stylename[0].isdigit() or itf.stylename[0] == "-"
):
itf.stylename = f"p{itf.stylename}"

if dev not in ports_chassis:
ports_chassis[dev] = []
ports_chassis[dev].append(itf)
Expand Down Expand Up @@ -55,7 +63,9 @@ def prepare(obj):
device_type=obj.device_type
).grid_template_area
modules[1] = obj.modules.all()
ports_chassis = process_interfaces(obj.interfaces.all(), ports_chassis, 1)
ports_chassis = process_interfaces(
obj.interfaces.all(), ports_chassis, obj.name
)
ports_chassis = process_ports(obj.frontports.all(), ports_chassis, "Front")
ports_chassis = process_ports(obj.rearports.all(), ports_chassis, "Rear")
ports_chassis = process_ports(
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="netbox-device-view",
version="0.1.9",
version="0.1.10-alpha",
description="NetBox Device View plugin",
packages=find_packages(),
author="Peter Baumert",
Expand All @@ -14,7 +14,7 @@
install_requires=[],
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/peterbaumert/netbox-device-view",
url="https://github.com/cmcknz77/netbox-device-view",
keywords=["netbox", "netbox-plugin"],
classifiers=[
"Framework :: Django",
Expand Down
Loading