2015-01-26 10:33:01 +01:00
|
|
|
"""
|
|
|
|
This module defines common view code to be used by multiple gnuviechadmin apps.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
from __future__ import absolute_import
|
2015-01-26 10:33:01 +01:00
|
|
|
|
|
|
|
from django.shortcuts import get_object_or_404
|
2023-02-18 22:46:48 +01:00
|
|
|
|
2015-01-26 10:33:01 +01:00
|
|
|
from hostingpackages.models import CustomerHostingPackage
|
|
|
|
|
|
|
|
|
|
|
|
class HostingPackageAndCustomerMixin(object):
|
|
|
|
"""
|
|
|
|
Mixin for views that gets the hosting package instance from the URL
|
|
|
|
keyword argument 'package'.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
|
|
|
|
hosting_package_kwarg = "package"
|
2015-01-26 10:33:01 +01:00
|
|
|
"""Keyword argument used to find the hosting package in the URL."""
|
|
|
|
|
2015-02-01 02:11:07 +01:00
|
|
|
hostingpackage = None
|
|
|
|
|
2015-01-26 10:33:01 +01:00
|
|
|
def get_hosting_package(self):
|
2015-02-01 02:11:07 +01:00
|
|
|
if self.hostingpackage is None:
|
|
|
|
self.hostingpackage = get_object_or_404(
|
2023-02-18 22:46:48 +01:00
|
|
|
CustomerHostingPackage, pk=int(self.kwargs[self.hosting_package_kwarg])
|
|
|
|
)
|
2015-02-01 02:11:07 +01:00
|
|
|
return self.hostingpackage
|
2015-01-26 10:33:01 +01:00
|
|
|
|
|
|
|
def get_customer_object(self):
|
|
|
|
return self.get_hosting_package().customer
|