Implement get_object for invoice detail + url fix
This commit is contained in:
parent
247bbe622f
commit
ba9e554881
2 changed files with 31 additions and 2 deletions
|
@ -9,7 +9,7 @@ from .views import (
|
||||||
HostingPricingView, CreateVirtualMachinesView, HostingBillListView,
|
HostingPricingView, CreateVirtualMachinesView, HostingBillListView,
|
||||||
HostingBillDetailView, SSHKeyDeleteView, SSHKeyCreateView, SSHKeyListView,
|
HostingBillDetailView, SSHKeyDeleteView, SSHKeyCreateView, SSHKeyListView,
|
||||||
SSHKeyChoiceView, DashboardView, SettingsView, ResendActivationEmailView,
|
SSHKeyChoiceView, DashboardView, SettingsView, ResendActivationEmailView,
|
||||||
InvoiceListView
|
InvoiceListView, InvoiceDetailView
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ urlpatterns = [
|
||||||
name='order-confirmation'),
|
name='order-confirmation'),
|
||||||
url(r'orders/(?P<pk>\d+)/?$', OrdersHostingDetailView.as_view(),
|
url(r'orders/(?P<pk>\d+)/?$', OrdersHostingDetailView.as_view(),
|
||||||
name='orders'),
|
name='orders'),
|
||||||
url(r'invoices/(?P<pk>\d+)/?$', OrdersHostingDetailView.as_view(),
|
url(r'invoices/(?P<invoice_id>[-\w]+)/?$', InvoiceDetailView.as_view(),
|
||||||
name='invoices'),
|
name='invoices'),
|
||||||
url(r'bills/?$', HostingBillListView.as_view(), name='bills'),
|
url(r'bills/?$', HostingBillListView.as_view(), name='bills'),
|
||||||
url(r'bills/(?P<pk>\d+)/?$', HostingBillDetailView.as_view(),
|
url(r'bills/(?P<pk>\d+)/?$', HostingBillDetailView.as_view(),
|
||||||
|
|
|
@ -1163,6 +1163,35 @@ class InvoiceListView(LoginRequiredMixin, ListView):
|
||||||
return super(InvoiceListView, self).get(request, *args, **kwargs)
|
return super(InvoiceListView, self).get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class InvoiceDetailView(LoginRequiredMixin, DetailView):
|
||||||
|
template_name = "hosting/invoice-detail.html"
|
||||||
|
context_object_name = "invoice"
|
||||||
|
login_url = reverse_lazy('hosting:login')
|
||||||
|
permission_required = ['view_monthlyhostingbill']
|
||||||
|
model = MonthlyHostingBill
|
||||||
|
|
||||||
|
def get_object(self, queryset=None):
|
||||||
|
invoice_id = self.kwargs.get('invoice_id')
|
||||||
|
try:
|
||||||
|
invoice_obj = MonthlyHostingBill.objects.get(invoice_number=invoice_id)
|
||||||
|
logger.debug("Found MHB for id {invoice_id}".format(
|
||||||
|
invoice_id=invoice_id
|
||||||
|
))
|
||||||
|
if self.request.user.has_perm(
|
||||||
|
self.permission_required[0], invoice_obj
|
||||||
|
) or self.request.user.email == settings.ADMIN_EMAIL:
|
||||||
|
logger.debug("User has permission to invoice_obj")
|
||||||
|
else:
|
||||||
|
logger.error("User does not have permission to access")
|
||||||
|
invoice_obj = None
|
||||||
|
except HostingOrder.DoesNotExist:
|
||||||
|
logger.debug("MHB not found for id {invoice_id}".format(
|
||||||
|
invoice_id=invoice_id
|
||||||
|
))
|
||||||
|
invoice_obj = None
|
||||||
|
return invoice_obj
|
||||||
|
|
||||||
|
|
||||||
class OrdersHostingDeleteView(LoginRequiredMixin, DeleteView):
|
class OrdersHostingDeleteView(LoginRequiredMixin, DeleteView):
|
||||||
login_url = reverse_lazy('hosting:login')
|
login_url = reverse_lazy('hosting:login')
|
||||||
success_url = reverse_lazy('hosting:orders')
|
success_url = reverse_lazy('hosting:orders')
|
||||||
|
|
Loading…
Reference in a new issue