-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v4.3.7
Feature type
New functionality
Proposed functionality
Introduce a set of Python class which can be utilities both in core NetBox and in plugins to render standardized data components within HTML templates. Proposed components include:
- Attribute tables
- Custom field tables
- Related object counts
- Related object lists
- Markdown content
For example, an attribute table might defined like this:
site_details = AttributeTable({
'Region': Attr(site.region, linkify=True),
'Group': Attr(site.group, linkify=True),
'Status': Badge(site.status, color=site.get_status_color()),
'Tenant': Attr(site.tenant, nested=True),
'Facility': Attr(site.facility),
}, title='Site')When cast as a string within a template (e.g. {{ site_details }}), the AttributeTable instance will render the HTML necessary to construct a complete table element with the appropriate CSS styling applied. Similar approaches can be taken for the other proposed components.
Use case
Currently, HTML templates used to display individual objects generally employ a base template (i.e. generic/object.html) which is extended with arbitrary HTML to display the desired content. The resulting templates, while fully functional, are subject to drift as the structuring and styling of the NetBox UI evolves over time. It can also be quite tedious to build out these components using raw HTML; a class-based approach greatly simplifies and speeds up the process.
Database changes
N/A
External dependencies
N/A