implement caching for get_hosting_package

This commit is contained in:
Jan Dittberner 2015-02-01 02:11:07 +01:00
parent 832a611602
commit 5e1f34c9d8
2 changed files with 10 additions and 3 deletions

View file

@ -17,10 +17,14 @@ class HostingPackageAndCustomerMixin(object):
hosting_package_kwarg = 'package'
"""Keyword argument used to find the hosting package in the URL."""
hostingpackage = None
def get_hosting_package(self):
return get_object_or_404(
CustomerHostingPackage,
pk=int(self.kwargs[self.hosting_package_kwarg]))
if self.hostingpackage is None:
self.hostingpackage = get_object_or_404(
CustomerHostingPackage,
pk=int(self.kwargs[self.hosting_package_kwarg]))
return self.hostingpackage
def get_customer_object(self):
return self.get_hosting_package().customer