gva/gnuviechadmin/gvawebcore/views.py
Jan Dittberner 4af1a39ca4 Upgrade to Django 3.2
- update dependencies
- fix deprecation warnings
- fix tests
- skip some tests that need more work
- reformat changed code with isort and black
2023-02-18 22:46:48 +01:00

32 lines
895 B
Python

"""
This module defines common view code to be used by multiple gnuviechadmin apps.
"""
from __future__ import absolute_import
from django.shortcuts import get_object_or_404
from hostingpackages.models import CustomerHostingPackage
class HostingPackageAndCustomerMixin(object):
"""
Mixin for views that gets the hosting package instance from the URL
keyword argument 'package'.
"""
hosting_package_kwarg = "package"
"""Keyword argument used to find the hosting package in the URL."""
hostingpackage = None
def get_hosting_package(self):
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