From 6f252def5d9aa7bda7ea9bb99036a69cb3b1114d Mon Sep 17 00:00:00 2001 From: Modulos Date: Sat, 6 May 2017 15:16:10 +0200 Subject: [PATCH] Return error if HostingBill object does not exist --- hosting/templates/hosting/bill_error.html | 14 ++++++++++++++ hosting/views.py | 8 ++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 hosting/templates/hosting/bill_error.html diff --git a/hosting/templates/hosting/bill_error.html b/hosting/templates/hosting/bill_error.html new file mode 100644 index 00000000..5374ecb5 --- /dev/null +++ b/hosting/templates/hosting/bill_error.html @@ -0,0 +1,14 @@ +{% extends "hosting/base_short.html" %} +{% load staticfiles bootstrap3 %} +{% load i18n %} +{% block content %} + +
+
+

Error

+

Could not get HostingBill object for client.

+

Please create a HostingBill object via the admin page

+
+
+{% endblock %} + diff --git a/hosting/views.py b/hosting/views.py index b552063a..b5a18597 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -424,10 +424,14 @@ class HostingBillDetailView(PermissionRequiredMixin, LoginRequiredMixin, DetailV return HostingBill.objects.filter(customer__id=pk).first() def get_context_data(self, **kwargs): - # Get User - user_email = self.object.customer.user.email # Get context context = super(DetailView, self).get_context_data(**kwargs) + # Get User + try: + user_email = self.object.customer.user.email + except AttributeError: + self.template_name = 'hosting/bill_error.html' + return context # Add VMs to context context['vms'] = []