mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-20 20:32:25 -06:00
Closes #6097: Redirect old slug-based object views
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from django.contrib.auth.mixins import AccessMixin
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.urls import reverse
|
||||
from django.urls.exceptions import NoReverseMatch
|
||||
from django.utils.http import is_safe_url
|
||||
from django.views.generic import View
|
||||
|
||||
from .permissions import resolve_permission
|
||||
|
||||
@@ -123,3 +125,14 @@ class GetReturnURLMixin:
|
||||
|
||||
# If all else fails, return home. Ideally this should never happen.
|
||||
return reverse('home')
|
||||
|
||||
|
||||
#
|
||||
# Views
|
||||
#
|
||||
|
||||
class SlugRedirectView(View):
|
||||
|
||||
def get(self, request, model, slug):
|
||||
obj = get_object_or_404(model.objects.restrict(request.user, 'view'), slug=slug)
|
||||
return redirect(obj.get_absolute_url())
|
||||
|
||||
Reference in New Issue
Block a user