Return error page if HostingBill is None

This commit is contained in:
Modulos 2017-05-08 01:56:02 +02:00
parent f871bb2aba
commit b4ec750728

View file

@ -510,10 +510,18 @@ class HostingBillDetailView(PermissionRequiredMixin, LoginRequiredMixin, DetailV
def get_object(self, queryset=None): def get_object(self, queryset=None):
#Get HostingBill for primary key (Select from customer users) #Get HostingBill for primary key (Select from customer users)
pk = self.kwargs['pk'] 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): def get_context_data(self, **kwargs):
# Get context # Get context
context = super(DetailView, self).get_context_data(**kwargs) context = super(DetailView, self).get_context_data(**kwargs)
# Get vms # Get vms
try:
context['vms'] = self.get_object().get_vms() context['vms'] = self.get_object().get_vms()
except:
pass
return context