-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[change] Use device name as node label in admin too if enabled #75
Related to #75
- Loading branch information
1 parent
07b6ceb
commit ca653de
Showing
8 changed files
with
184 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
openwisp_network_topology/integrations/device/overrides.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import swapper | ||
|
||
Node = swapper.load_model('topology', 'Node') | ||
Link = swapper.load_model('topology', 'Link') | ||
Topology = swapper.load_model('topology', 'Topology') | ||
|
||
|
||
def get_name(self): | ||
if hasattr(self, 'devicenode'): | ||
return self.devicenode.device.name | ||
return super(Node, self).get_name() | ||
|
||
|
||
def topology_get_nodes_queryset(self): | ||
""" | ||
Overrides Topology.get_nodes_queryset | ||
to avoid generating 2 additional queries for each node | ||
when using the name of the device as the node label | ||
""" | ||
return ( | ||
super(Topology, self) | ||
.get_nodes_queryset() | ||
.select_related('devicenode__device') | ||
.only( | ||
'id', | ||
'topology_id', | ||
'label', | ||
'addresses', | ||
'properties', | ||
'created', | ||
'modified', | ||
'devicenode__device__name', | ||
) | ||
) | ||
|
||
|
||
@classmethod | ||
def node_get_queryset(cls, qs): | ||
return ( | ||
super(Node, cls) | ||
.get_queryset(qs) | ||
.select_related('devicenode__device') | ||
.only( | ||
'id', | ||
'topology_id', | ||
'topology__label', | ||
'topology__parser', | ||
'organization__id', | ||
'organization__name', | ||
'organization__is_active', | ||
'label', | ||
'addresses', | ||
'devicenode__device__name', | ||
) | ||
) | ||
|
||
|
||
@classmethod | ||
def link_get_queryset(cls, qs): | ||
return ( | ||
super(Link, cls) | ||
.get_queryset(qs) | ||
.select_related('source__devicenode__device', 'target__devicenode__device') | ||
.only( | ||
'id', | ||
'topology_id', | ||
'topology__label', | ||
'topology__parser', | ||
'organization__id', | ||
'organization__name', | ||
'organization__is_active', | ||
'status', | ||
'cost', | ||
'cost_text', | ||
'source__addresses', | ||
'source__label', | ||
'source__devicenode__device__name', | ||
'target__addresses', | ||
'target__label', | ||
'target__devicenode__device__name', | ||
) | ||
) | ||
|
||
|
||
Node.get_name = get_name | ||
Node.get_queryset = node_get_queryset | ||
Link.get_queryset = link_get_queryset | ||
Topology.get_nodes_queryset = topology_get_nodes_queryset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters