move HostingPackageAndCustomerMixin to gvawebcore.views

This commit is contained in:
Jan Dittberner 2015-01-26 10:33:01 +01:00
parent 7bc26b261c
commit 638a6f6712
4 changed files with 37 additions and 21 deletions

View file

@ -1,6 +1,9 @@
Changelog Changelog
========= =========
* :support:`-` move HostingPackageAndCustomerMixin from managemails.views to
gvawebcore.views
* :release:`0.7.0 <2015-01-25>` * :release:`0.7.0 <2015-01-25>`
* :feature:`-` implement mail address target editing * :feature:`-` implement mail address target editing
* :feature:`-` implement mail address deletion * :feature:`-` implement mail address deletion

View file

@ -9,3 +9,10 @@
.. automodule:: gvawebcore.forms .. automodule:: gvawebcore.forms
:members: :members:
:py:mod:`views <gvawebcore.views>`
----------------------------------
.. automodule:: gvawebcore.views
:members:

View file

@ -0,0 +1,26 @@
"""
This module defines common view code to be used by multiple gnuviechadmin apps.
"""
from __future__ import absolute_import, unicode_literals
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."""
def get_hosting_package(self):
return get_object_or_404(
CustomerHostingPackage,
pk=int(self.kwargs[self.hosting_package_kwarg]))
def get_customer_object(self):
return self.get_hosting_package().customer

View file

@ -15,8 +15,7 @@ from django.views.generic.edit import (
from django.contrib import messages from django.contrib import messages
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
from gvawebcore.views import HostingPackageAndCustomerMixin
from hostingpackages.models import CustomerHostingPackage
from domains.models import MailDomain from domains.models import MailDomain
from .forms import ( from .forms import (
@ -33,25 +32,6 @@ from .models import (
) )
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."""
def get_hosting_package(self):
return get_object_or_404(
CustomerHostingPackage,
pk=int(self.kwargs[self.hosting_package_kwarg]))
def get_customer_object(self):
return self.get_hosting_package().customer
class CreateMailbox( class CreateMailbox(
HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, CreateView HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, CreateView
): ):