Skip to content

Conversation

@dvigne
Copy link
Contributor

@dvigne dvigne commented Nov 13, 2022

Fix for feature request 10904 thanks to @TheZackCodec

Fixes: #10904

When rendering the SVG, checks if a custom color is defined and renders that color on the termination.

Fix for feature request 10904 thanks to @TheZackCodec
@dvigne dvigne changed the title Added Colors to SVG for Front and Reaer Ports Added Colors to SVG for Front and Rear Ports Nov 13, 2022
@dvigne dvigne changed the title Added Colors to SVG for Front and Rear Ports Closes #10904: Added Colors to SVG for Front and Rear Ports Nov 14, 2022
Comment on lines 169 to 171
if(hasattr(instance, 'get_color') and instance.get_color()):
return instance.get_color()
return 'f0f0f0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a method here. You can just do:

Suggested change
if(hasattr(instance, 'get_color') and instance.get_color()):
return instance.get_color()
return 'f0f0f0'
return getattr(instance, 'color', 'f0f0f0')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much cleaner and I like the syntax a lot better, but what I'm finding is that the model has blank=True set for both the FrontPort and RearPort models and this leads to an empty string being stored in the database. This logic fails because it always has the color attribute, it just happens to be a blank string.

A quick solution for this would be change that one line to something like below, but I'm open to suggestions.

Suggested change
if(hasattr(instance, 'get_color') and instance.get_color()):
return instance.get_color()
return 'f0f0f0'
return getattr(instance, 'color', 'f0f0f0') or 'f0f0f0'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works.

@jeremystretch jeremystretch merged commit a2007a4 into netbox-community:develop Nov 16, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Render Specified Front and Rear Port Colors During Cable Trace

2 participants