From b4ec750728a4c9dfe90c3eeca3488f6bdf5bc1b5 Mon Sep 17 00:00:00 2001 From: Modulos Date: Mon, 8 May 2017 01:56:02 +0200 Subject: [PATCH] Return error page if HostingBill is None --- hosting/views.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 91b92667..4c66f40e 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -510,10 +510,18 @@ class HostingBillDetailView(PermissionRequiredMixin, LoginRequiredMixin, DetailV def get_object(self, queryset=None): #Get HostingBill for primary key (Select from customer users) pk = self.kwargs['pk'] - return HostingBill.objects.filter(customer__id=pk).first() + object = HostingBill.objects.filter(customer__id=pk).first() + if object is None: + self.template_name = 'hosting/bill_error.html' + return object def get_context_data(self, **kwargs): # Get context context = super(DetailView, self).get_context_data(**kwargs) # Get vms - context['vms'] = self.get_object().get_vms() + try: + context['vms'] = self.get_object().get_vms() + except: + pass + + return context