Skip to content

Commit

Permalink
Closes netbox-community#771: Don't automatically redirect user when o…
Browse files Browse the repository at this point in the history
…nly one object is returned in a list
  • Loading branch information
jeremystretch committed Jan 4, 2017
1 parent 7f297b4 commit 8154ae3
Showing 1 changed file with 0 additions and 10 deletions.
10 changes: 0 additions & 10 deletions netbox/utilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,13 @@ class ObjectListView(View):
table: The django-tables2 Table used to render the objects list
edit_permissions: Editing controls are displayed only if the user has these permissions
template_name: The name of the template
redirect_on_single_result: If True and the queryset returns only a single object, the user is automatically
redirected to that object
"""
queryset = None
filter = None
filter_form = None
table = None
edit_permissions = []
template_name = None
redirect_on_single_result = True

def get(self, request):

Expand Down Expand Up @@ -95,13 +92,6 @@ def get(self, request):
.format(self.queryset.model._meta.verbose_name_plural)
return response

# Attempt to redirect automatically if the search query returns a single result
if self.redirect_on_single_result and self.queryset.count() == 1 and request.GET:
try:
return HttpResponseRedirect(self.queryset[0].get_absolute_url())
except AttributeError:
pass

# Provide a hook to tweak the queryset based on the request immediately prior to rendering the object list
self.queryset = self.alter_queryset(request)

Expand Down

0 comments on commit 8154ae3

Please sign in to comment.