Converted home view to a CBV

This commit is contained in:
Jeremy Stretch 2017-05-19 16:03:51 -04:00
parent c02c834d94
commit a4461720fc
2 changed files with 37 additions and 33 deletions

View File

@ -5,7 +5,7 @@ from django.conf.urls import include, url
from django.contrib import admin
from django.views.static import serve
from netbox.views import APIRootView, home, handle_500, SearchView, trigger_500
from netbox.views import APIRootView, handle_500, HomeView, SearchView, trigger_500
from users.views import LoginView, LogoutView
@ -15,7 +15,7 @@ swagger_view = get_swagger_view(title='NetBox API')
_patterns = [
# Base views
url(r'^$', home, name='home'),
url(r'^$', HomeView.as_view(), name='home'),
url(r'^search/$', SearchView.as_view(), name='search'),
# Login/logout

View File

@ -115,7 +115,10 @@ SEARCH_TYPES = OrderedDict((
))
def home(request):
class HomeView(View):
template_name = 'home.html'
def get(self, request):
stats = {
@ -146,7 +149,7 @@ def home(request):
}
return render(request, 'home.html', {
return render(request, self.template_name, {
'search_form': SearchForm(),
'stats': stats,
'topology_maps': TopologyMap.objects.filter(site__isnull=True),
@ -235,5 +238,6 @@ def trigger_500(request):
"""
Hot-wired method of triggering a server error to test reporting
"""
raise Exception("Congratulations, you've triggered an exception! Go tell all your friends what an exceptional "
"person you are.")
raise Exception(
"Congratulations, you've triggered an exception! Go tell all your friends what an exceptional person you are."
)