-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3231 from Uninett/feature/maintenance-improve-del…
…eted-component-display Refactor maintenance task views to improve display of deleted components #3230
- Loading branch information
Showing
11 changed files
with
287 additions
and
306 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve description of deleted maintenance components |
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,68 @@ | ||
# | ||
# Copyright (C) 2024 Sikt | ||
# | ||
# This file is part of Network Administration Visualized (NAV). | ||
# | ||
# NAV is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License version 3 as published by | ||
# the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. You should have received a copy of the GNU General Public | ||
# License along with NAV. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
"""Template tags for the maintenance tool""" | ||
from django import template | ||
|
||
from nav.web.maintenance.utils import MissingComponent | ||
|
||
register = template.Library() | ||
|
||
|
||
@register.filter | ||
def model_verbose_name(model): | ||
"""Returns the capitalized verbose name of a model""" | ||
if not model: | ||
return | ||
name = model._meta.verbose_name | ||
# Keep original capitalization, if any, otherwise apply our own | ||
# e.g. don't turn "IP Device" into "Ip device", but do turn "room" into "Room" | ||
return name if name[0].isupper() else name.capitalize() | ||
|
||
|
||
@register.filter | ||
def component_name(component): | ||
"""Returns an identifying name of a model object used as a maintenance component""" | ||
if not component: | ||
return "" | ||
if hasattr(component, "sysname"): | ||
return component.sysname | ||
if hasattr(component, "handler"): | ||
return component.handler | ||
if isinstance(component, MissingComponent): | ||
return str(component) | ||
return component.pk | ||
|
||
|
||
@register.filter | ||
def component_description(component): | ||
"""Returns a description of a component useful as a link title tooltip. Returns | ||
an empty string if there is no further description than the component's name. | ||
""" | ||
if isinstance(component, MissingComponent): | ||
return str(component) | ||
if hasattr(component, "ip"): | ||
return str(component.ip) | ||
return getattr(component, "description", "") | ||
|
||
|
||
@register.filter | ||
def component_db_table(component): | ||
"""Returns the database table name of a model object used as a maintenance | ||
component. | ||
""" | ||
if not component: | ||
return "" | ||
return component._meta.db_table |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- Add column to maint_component table to keep descriptions of components that can no longer referenced | ||
ALTER TABLE maint_component ADD COLUMN description VARCHAR; | ||
|
||
UPDATE maint_component c | ||
SET description = n.sysname | ||
FROM netbox n | ||
WHERE c.key = 'netbox' AND c.value = n.netboxid::text; | ||
|
||
UPDATE maint_component c | ||
SET description = s.handler || ' at ' || n.sysname | ||
FROM service s | ||
JOIN netbox n ON s.netboxid = n.netboxid | ||
WHERE c.key = 'service' AND c.value = s.serviceid::text; |
Oops, something went wrong.