From 638a6f6712809349793df3697e8c13f6c700e97c Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Mon, 26 Jan 2015 10:33:01 +0100 Subject: [PATCH] move HostingPackageAndCustomerMixin to gvawebcore.views --- docs/changelog.rst | 3 +++ docs/code/gvawebcore.rst | 7 +++++++ gnuviechadmin/gvawebcore/views.py | 26 ++++++++++++++++++++++++++ gnuviechadmin/managemails/views.py | 22 +--------------------- 4 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 gnuviechadmin/gvawebcore/views.py diff --git a/docs/changelog.rst b/docs/changelog.rst index db3a407..167834b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,9 @@ Changelog ========= +* :support:`-` move HostingPackageAndCustomerMixin from managemails.views to + gvawebcore.views + * :release:`0.7.0 <2015-01-25>` * :feature:`-` implement mail address target editing * :feature:`-` implement mail address deletion diff --git a/docs/code/gvawebcore.rst b/docs/code/gvawebcore.rst index 7fdd1b0..db3d760 100644 --- a/docs/code/gvawebcore.rst +++ b/docs/code/gvawebcore.rst @@ -9,3 +9,10 @@ .. automodule:: gvawebcore.forms :members: + + +:py:mod:`views ` +---------------------------------- + +.. automodule:: gvawebcore.views + :members: diff --git a/gnuviechadmin/gvawebcore/views.py b/gnuviechadmin/gvawebcore/views.py new file mode 100644 index 0000000..6e22e29 --- /dev/null +++ b/gnuviechadmin/gvawebcore/views.py @@ -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 diff --git a/gnuviechadmin/managemails/views.py b/gnuviechadmin/managemails/views.py index 8fed77f..e5590b1 100644 --- a/gnuviechadmin/managemails/views.py +++ b/gnuviechadmin/managemails/views.py @@ -15,8 +15,7 @@ from django.views.generic.edit import ( from django.contrib import messages from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin - -from hostingpackages.models import CustomerHostingPackage +from gvawebcore.views import HostingPackageAndCustomerMixin from domains.models import MailDomain 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( HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, CreateView ):