From 1024f9775678a982e45c167bc9db45d40664c57d Mon Sep 17 00:00:00 2001 From: Johanna England Date: Wed, 28 Aug 2024 12:59:25 +0200 Subject: [PATCH] Remove reverse_lazy helper function We can now use django's --- python/nav/web/seeddb/__init__.py | 16 ---------------- python/nav/web/seeddb/page/cabling.py | 4 +++- python/nav/web/seeddb/page/location.py | 3 ++- .../seeddb/page/management_profile/__init__.py | 2 +- python/nav/web/seeddb/page/netbox/__init__.py | 3 ++- python/nav/web/seeddb/page/netbox/edit.py | 7 +++---- python/nav/web/seeddb/page/netboxgroup.py | 6 ++++-- python/nav/web/seeddb/page/netboxtype.py | 4 +++- python/nav/web/seeddb/page/organization.py | 3 ++- python/nav/web/seeddb/page/patch/__init__.py | 3 ++- python/nav/web/seeddb/page/prefix.py | 4 ++-- python/nav/web/seeddb/page/room.py | 4 ++-- python/nav/web/seeddb/page/service/__init__.py | 4 +++- python/nav/web/seeddb/page/usage.py | 3 ++- python/nav/web/seeddb/page/vendor.py | 3 ++- python/nav/web/seeddb/page/vlan.py | 3 ++- 16 files changed, 35 insertions(+), 37 deletions(-) diff --git a/python/nav/web/seeddb/__init__.py b/python/nav/web/seeddb/__init__.py index 1c65290f27..5d850c6490 100644 --- a/python/nav/web/seeddb/__init__.py +++ b/python/nav/web/seeddb/__init__.py @@ -15,26 +15,10 @@ # along with NAV. If not, see . # -from django.urls import reverse from nav.web.seeddb.constants import TITLE_DEFAULT, NAVPATH_DEFAULT -def reverse_lazy(*args, **kwargs): - # Lazy reverse will become part of the Django framework in future releases. - class Proxy(object): - def __init__(self, *args, **kwargs): - self.args = args - self.kwargs = kwargs - - def __str__(self): - if not hasattr(self, 'reverse_url'): - self.reverse_url = reverse(*self.args, **self.kwargs) - return self.reverse_url - - return Proxy(*args, **kwargs) - - class SeeddbInfo(object): active = {'index': True} active_page = '' diff --git a/python/nav/web/seeddb/page/cabling.py b/python/nav/web/seeddb/page/cabling.py index d85576f29d..3edfe3ff9a 100644 --- a/python/nav/web/seeddb/page/cabling.py +++ b/python/nav/web/seeddb/page/cabling.py @@ -15,12 +15,14 @@ # along with NAV. If not, see . # +from django.urls import reverse_lazy + from nav.models.cabling import Cabling from nav.models.manage import Room from nav.bulkparse import CablingBulkParser from nav.bulkimport import CablingImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher, not_implemented from nav.web.seeddb.utils.list import render_list diff --git a/python/nav/web/seeddb/page/location.py b/python/nav/web/seeddb/page/location.py index f606f2d631..7307bd2ab9 100644 --- a/python/nav/web/seeddb/page/location.py +++ b/python/nav/web/seeddb/page/location.py @@ -17,12 +17,13 @@ # from django.shortcuts import render +from django.urls import reverse_lazy from nav.models.manage import Location from nav.bulkparse import LocationBulkParser from nav.bulkimport import LocationImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.forms import LocationForm from nav.web.seeddb.page import view_switcher, not_implemented diff --git a/python/nav/web/seeddb/page/management_profile/__init__.py b/python/nav/web/seeddb/page/management_profile/__init__.py index 979b09bae4..943f62c956 100644 --- a/python/nav/web/seeddb/page/management_profile/__init__.py +++ b/python/nav/web/seeddb/page/management_profile/__init__.py @@ -26,7 +26,7 @@ from nav.bulkimport import ManagementProfileImporter from nav.web.message import new_message, Messages -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher from nav.web.seeddb.utils.list import render_list diff --git a/python/nav/web/seeddb/page/netbox/__init__.py b/python/nav/web/seeddb/page/netbox/__init__.py index 19bb38e561..bc6574abd7 100644 --- a/python/nav/web/seeddb/page/netbox/__init__.py +++ b/python/nav/web/seeddb/page/netbox/__init__.py @@ -18,12 +18,13 @@ import datetime from django.db import transaction from django.contrib.postgres.aggregates import ArrayAgg +from django.urls import reverse_lazy from nav.models.manage import Netbox from nav.bulkparse import NetboxBulkParser from nav.bulkimport import NetboxImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher from nav.web.seeddb.utils.list import render_list diff --git a/python/nav/web/seeddb/page/netbox/edit.py b/python/nav/web/seeddb/page/netbox/edit.py index c048f1856c..5687e9c47f 100644 --- a/python/nav/web/seeddb/page/netbox/edit.py +++ b/python/nav/web/seeddb/page/netbox/edit.py @@ -23,11 +23,11 @@ from socket import error as SocketError import logging -from django.urls import reverse -from django.http import HttpResponse, JsonResponse, Http404 -from django.shortcuts import get_object_or_404, redirect, render from django.db import transaction from django.contrib import messages +from django.http import HttpResponse, JsonResponse, Http404 +from django.shortcuts import get_object_or_404, redirect, render +from django.urls import reverse, reverse_lazy from nav.auditlog.models import LogEntry from nav.models.manage import Netbox, NetboxCategory, NetboxType, NetboxProfile @@ -37,7 +37,6 @@ from nav.Snmp.profile import get_snmp_session_for_profile from nav import napalm from nav.util import is_valid_ip -from nav.web.seeddb import reverse_lazy from nav.web.seeddb.utils.edit import resolve_ip_and_sysname from nav.web.seeddb.page.netbox import NetboxInfo as NI from nav.web.seeddb.page.netbox.forms import NetboxModelForm diff --git a/python/nav/web/seeddb/page/netboxgroup.py b/python/nav/web/seeddb/page/netboxgroup.py index 22e6fb8ddb..bf0b126c9b 100644 --- a/python/nav/web/seeddb/page/netboxgroup.py +++ b/python/nav/web/seeddb/page/netboxgroup.py @@ -34,12 +34,14 @@ # import logging -from django.http import JsonResponse + +from django.urls import reverse_lazy + from nav.models.manage import NetboxGroup, Netbox from nav.bulkparse import NetboxGroupBulkParser from nav.bulkimport import NetboxGroupImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher, not_implemented from nav.web.seeddb.utils.list import render_list diff --git a/python/nav/web/seeddb/page/netboxtype.py b/python/nav/web/seeddb/page/netboxtype.py index 4e506fac56..1a8974e2c7 100644 --- a/python/nav/web/seeddb/page/netboxtype.py +++ b/python/nav/web/seeddb/page/netboxtype.py @@ -15,11 +15,13 @@ # along with NAV. If not, see . # +from django.urls import reverse_lazy + from nav.models.manage import NetboxType from nav.bulkparse import NetboxTypeBulkParser from nav.bulkimport import NetboxTypeImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher, not_implemented from nav.web.seeddb.utils.list import render_list diff --git a/python/nav/web/seeddb/page/organization.py b/python/nav/web/seeddb/page/organization.py index b4a673d1fd..a42a48b406 100644 --- a/python/nav/web/seeddb/page/organization.py +++ b/python/nav/web/seeddb/page/organization.py @@ -16,12 +16,13 @@ # from django.shortcuts import render +from django.urls import reverse_lazy from nav.models.manage import Organization from nav.bulkparse import OrgBulkParser from nav.bulkimport import OrgImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher from nav.web.seeddb.utils.edit import render_edit diff --git a/python/nav/web/seeddb/page/patch/__init__.py b/python/nav/web/seeddb/page/patch/__init__.py index 3cf9a8141f..c6e268df55 100644 --- a/python/nav/web/seeddb/page/patch/__init__.py +++ b/python/nav/web/seeddb/page/patch/__init__.py @@ -21,6 +21,7 @@ from django import forms from django.http import HttpResponse from django.shortcuts import render, get_object_or_404 +from django.urls import reverse_lazy from django.views.decorators.http import require_POST from nav.models.cabling import Patch, Cabling @@ -28,7 +29,7 @@ from nav.bulkparse import PatchBulkParser from nav.bulkimport import PatchImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher, not_implemented from nav.web.seeddb.utils.list import render_list diff --git a/python/nav/web/seeddb/page/prefix.py b/python/nav/web/seeddb/page/prefix.py index 7669c158e1..8e4d01fcf9 100644 --- a/python/nav/web/seeddb/page/prefix.py +++ b/python/nav/web/seeddb/page/prefix.py @@ -23,7 +23,7 @@ from django.db import transaction from django.shortcuts import render from django.http import HttpResponseRedirect -from django.urls import reverse +from django.urls import reverse, reverse_lazy from nav.web.message import new_message, Messages @@ -32,7 +32,7 @@ from nav.bulkparse import PrefixBulkParser from nav.bulkimport import PrefixImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher, not_implemented from nav.web.seeddb.utils.list import render_list diff --git a/python/nav/web/seeddb/page/room.py b/python/nav/web/seeddb/page/room.py index 03abe94cac..ccf25bb972 100644 --- a/python/nav/web/seeddb/page/room.py +++ b/python/nav/web/seeddb/page/room.py @@ -17,13 +17,13 @@ # """Forms and view functions for SeedDB's Room view""" -from django.urls import reverse +from django.urls import reverse_lazy from nav.models.manage import Room from nav.bulkparse import RoomBulkParser from nav.bulkimport import RoomImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher from nav.web.seeddb.utils.list import render_list diff --git a/python/nav/web/seeddb/page/service/__init__.py b/python/nav/web/seeddb/page/service/__init__.py index 96ede6d6c8..9e86963a65 100644 --- a/python/nav/web/seeddb/page/service/__init__.py +++ b/python/nav/web/seeddb/page/service/__init__.py @@ -15,11 +15,13 @@ # along with NAV. If not, see . # +from django.urls import reverse_lazy + from nav.models.service import Service from nav.bulkparse import ServiceBulkParser from nav.bulkimport import ServiceImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher, not_implemented from nav.web.seeddb.utils.list import render_list diff --git a/python/nav/web/seeddb/page/usage.py b/python/nav/web/seeddb/page/usage.py index 34a1f92deb..f2b6045933 100644 --- a/python/nav/web/seeddb/page/usage.py +++ b/python/nav/web/seeddb/page/usage.py @@ -17,12 +17,13 @@ """Module containing all things regarding usages in seeddb""" from django import forms +from django.urls import reverse_lazy from nav.models.manage import Usage from nav.bulkparse import UsageBulkParser from nav.bulkimport import UsageImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher, not_implemented from nav.web.seeddb.utils.list import render_list diff --git a/python/nav/web/seeddb/page/vendor.py b/python/nav/web/seeddb/page/vendor.py index 10fdc5baf0..3b2d30b302 100644 --- a/python/nav/web/seeddb/page/vendor.py +++ b/python/nav/web/seeddb/page/vendor.py @@ -17,12 +17,13 @@ """Module containing everything regarding vendors in SeedDB""" from django import forms +from django.urls import reverse_lazy from nav.models.manage import Vendor from nav.bulkparse import VendorBulkParser from nav.bulkimport import VendorImporter -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.constants import SEEDDB_EDITABLE_MODELS from nav.web.seeddb.page import view_switcher, not_implemented from nav.web.seeddb.utils.list import render_list diff --git a/python/nav/web/seeddb/page/vlan.py b/python/nav/web/seeddb/page/vlan.py index 2d70d7c525..70556dda16 100644 --- a/python/nav/web/seeddb/page/vlan.py +++ b/python/nav/web/seeddb/page/vlan.py @@ -17,6 +17,7 @@ # from django import forms +from django.urls import reverse_lazy from crispy_forms.helper import FormHelper from crispy_forms_foundation.layout import Layout, Row, Column, Fieldset @@ -24,7 +25,7 @@ from nav.models.manage import Vlan, NetType, Organization, Usage -from nav.web.seeddb import SeeddbInfo, reverse_lazy +from nav.web.seeddb import SeeddbInfo from nav.web.seeddb.utils.list import render_list from nav.web.seeddb.utils.edit import render_edit