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
This commit is contained in:
parent
0f18e59d67
commit
4af1a39ca4
93 changed files with 3598 additions and 2725 deletions
|
@ -2,28 +2,17 @@
|
|||
This module defines views related to hosting packages.
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from __future__ import absolute_import
|
||||
|
||||
from braces.views import LoginRequiredMixin, StaffuserRequiredMixin
|
||||
from django.conf import settings
|
||||
from django.http import Http404
|
||||
from django.shortcuts import redirect, get_object_or_404
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import (
|
||||
DetailView,
|
||||
ListView,
|
||||
)
|
||||
from django.views.generic.edit import (
|
||||
CreateView,
|
||||
FormView,
|
||||
)
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from braces.views import (
|
||||
LoginRequiredMixin,
|
||||
StaffuserRequiredMixin,
|
||||
)
|
||||
|
||||
from django.http import Http404
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import DetailView, ListView
|
||||
from django.views.generic.edit import CreateView, FormView
|
||||
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
||||
|
||||
from .forms import (
|
||||
|
@ -41,24 +30,24 @@ from .models import (
|
|||
)
|
||||
|
||||
|
||||
class CreateHostingPackage(
|
||||
LoginRequiredMixin, StaffuserRequiredMixin, CreateView
|
||||
):
|
||||
class CreateHostingPackage(LoginRequiredMixin, StaffuserRequiredMixin, CreateView):
|
||||
"""
|
||||
Create a hosting package.
|
||||
|
||||
"""
|
||||
|
||||
model = CustomerHostingPackage
|
||||
raise_exception = True
|
||||
template_name_suffix = '_create'
|
||||
template_name_suffix = "_create"
|
||||
form_class = CreateHostingPackageForm
|
||||
|
||||
def form_valid(self, form):
|
||||
hostingpackage = form.save()
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Started setup of new hosting package {name}.').format(
|
||||
name=hostingpackage.name)
|
||||
_("Started setup of new hosting package {name}.").format(
|
||||
name=hostingpackage.name
|
||||
),
|
||||
)
|
||||
return redirect(hostingpackage)
|
||||
|
||||
|
@ -68,6 +57,7 @@ class CreateCustomerHostingPackage(CreateHostingPackage):
|
|||
Create a hosting package for a selected customer.
|
||||
|
||||
"""
|
||||
|
||||
form_class = CreateCustomerHostingPackageForm
|
||||
|
||||
def get_form_kwargs(self):
|
||||
|
@ -76,13 +66,11 @@ class CreateCustomerHostingPackage(CreateHostingPackage):
|
|||
return kwargs
|
||||
|
||||
def get_customer_object(self):
|
||||
return get_object_or_404(
|
||||
get_user_model(), username=self.kwargs['user'])
|
||||
return get_object_or_404(get_user_model(), username=self.kwargs["user"])
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(
|
||||
CreateCustomerHostingPackage, self).get_context_data(**kwargs)
|
||||
context['customer'] = self.get_customer_object()
|
||||
context = super(CreateCustomerHostingPackage, self).get_context_data(**kwargs)
|
||||
context["customer"] = self.get_customer_object()
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
|
@ -91,8 +79,9 @@ class CreateCustomerHostingPackage(CreateHostingPackage):
|
|||
hostingpackage.save()
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Started setup of new hosting package {name}.').format(
|
||||
name=hostingpackage.name)
|
||||
_("Started setup of new hosting package {name}.").format(
|
||||
name=hostingpackage.name
|
||||
),
|
||||
)
|
||||
return redirect(hostingpackage)
|
||||
|
||||
|
@ -102,30 +91,32 @@ class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView):
|
|||
This view is for showing details of a customer hosting package.
|
||||
|
||||
"""
|
||||
|
||||
model = CustomerHostingPackage
|
||||
context_object_name = 'hostingpackage'
|
||||
context_object_name = "hostingpackage"
|
||||
customer = None
|
||||
|
||||
def get_customer_object(self):
|
||||
if self.customer is None:
|
||||
self.customer = get_object_or_404(
|
||||
get_user_model(), username=self.kwargs['user'])
|
||||
get_user_model(), username=self.kwargs["user"]
|
||||
)
|
||||
return self.customer
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CustomerHostingPackageDetails, self).get_context_data(
|
||||
**kwargs)
|
||||
context.update({
|
||||
'customer': self.get_customer_object(),
|
||||
'uploadserver': settings.OSUSER_UPLOAD_SERVER,
|
||||
'databases': context['hostingpackage'].databases,
|
||||
'osuser': context['hostingpackage'].osuser,
|
||||
'hostingoptions':
|
||||
context['hostingpackage'].get_hostingoptions(),
|
||||
'domains': context['hostingpackage'].domains.all(),
|
||||
'mailboxes': context['hostingpackage'].mailboxes,
|
||||
})
|
||||
context['sshkeys'] = context['osuser'].sshpublickey_set.all()
|
||||
context = super(CustomerHostingPackageDetails, self).get_context_data(**kwargs)
|
||||
context.update(
|
||||
{
|
||||
"customer": self.get_customer_object(),
|
||||
"uploadserver": settings.OSUSER_UPLOAD_SERVER,
|
||||
"databases": context["hostingpackage"].databases,
|
||||
"osuser": context["hostingpackage"].osuser,
|
||||
"hostingoptions": context["hostingpackage"].get_hostingoptions(),
|
||||
"domains": context["hostingpackage"].domains.all(),
|
||||
"mailboxes": context["hostingpackage"].mailboxes,
|
||||
}
|
||||
)
|
||||
context["sshkeys"] = context["osuser"].sshpublickey_set.all()
|
||||
return context
|
||||
|
||||
|
||||
|
@ -136,8 +127,9 @@ class AllCustomerHostingPackageList(
|
|||
This view is used for showing a list of all hosting packages.
|
||||
|
||||
"""
|
||||
|
||||
model = CustomerHostingPackage
|
||||
template_name_suffix = '_admin_list'
|
||||
template_name_suffix = "_admin_list"
|
||||
|
||||
|
||||
class CustomerHostingPackageList(StaffOrSelfLoginRequiredMixin, ListView):
|
||||
|
@ -145,113 +137,128 @@ class CustomerHostingPackageList(StaffOrSelfLoginRequiredMixin, ListView):
|
|||
This view is used for showing a list of a customer's hosting packages.
|
||||
|
||||
"""
|
||||
|
||||
model = CustomerHostingPackage
|
||||
customer = None
|
||||
|
||||
def get_customer_object(self):
|
||||
if self.customer is None:
|
||||
self.customer = get_object_or_404(
|
||||
get_user_model(), username=self.kwargs['user'])
|
||||
get_user_model(), username=self.kwargs["user"]
|
||||
)
|
||||
return self.customer
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CustomerHostingPackageList, self).get_context_data(
|
||||
**kwargs)
|
||||
context['customer'] = self.get_customer_object()
|
||||
context = super(CustomerHostingPackageList, self).get_context_data(**kwargs)
|
||||
context["customer"] = self.get_customer_object()
|
||||
return context
|
||||
|
||||
def get_queryset(self):
|
||||
return super(CustomerHostingPackageList, self).get_queryset().filter(
|
||||
customer__username=self.kwargs['user'])
|
||||
return (
|
||||
super(CustomerHostingPackageList, self)
|
||||
.get_queryset()
|
||||
.filter(customer__username=self.kwargs["user"])
|
||||
)
|
||||
|
||||
|
||||
class HostingOptionChoices(
|
||||
LoginRequiredMixin, StaffuserRequiredMixin, DetailView
|
||||
):
|
||||
class HostingOptionChoices(LoginRequiredMixin, StaffuserRequiredMixin, DetailView):
|
||||
"""
|
||||
This view displays choices of hosting options for a customer hosting
|
||||
package.
|
||||
|
||||
"""
|
||||
|
||||
model = CustomerHostingPackage
|
||||
context_object_name = 'hostingpackage'
|
||||
template_name_suffix = '_option_choices'
|
||||
context_object_name = "hostingpackage"
|
||||
template_name_suffix = "_option_choices"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(HostingOptionChoices, self).get_context_data(
|
||||
**kwargs)
|
||||
context.update({
|
||||
'customer': self.get_object().customer,
|
||||
'hosting_options': (
|
||||
(_('Disk space'),
|
||||
[(option, 'diskspace') for option in
|
||||
DiskSpaceOption.objects.all()]),
|
||||
(_('Mailboxes'),
|
||||
[(option, 'mailboxes') for option in
|
||||
MailboxOption.objects.all()]),
|
||||
(_('Databases'),
|
||||
[(option, 'databases') for option in
|
||||
UserDatabaseOption.objects.all()]),
|
||||
),
|
||||
})
|
||||
context = super(HostingOptionChoices, self).get_context_data(**kwargs)
|
||||
context.update(
|
||||
{
|
||||
"customer": self.get_object().customer,
|
||||
"hosting_options": (
|
||||
(
|
||||
_("Disk space"),
|
||||
[
|
||||
(option, "diskspace")
|
||||
for option in DiskSpaceOption.objects.all()
|
||||
],
|
||||
),
|
||||
(
|
||||
_("Mailboxes"),
|
||||
[
|
||||
(option, "mailboxes")
|
||||
for option in MailboxOption.objects.all()
|
||||
],
|
||||
),
|
||||
(
|
||||
_("Databases"),
|
||||
[
|
||||
(option, "databases")
|
||||
for option in UserDatabaseOption.objects.all()
|
||||
],
|
||||
),
|
||||
),
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
|
||||
class AddHostingOption(
|
||||
LoginRequiredMixin, StaffuserRequiredMixin, FormView
|
||||
):
|
||||
template_name = 'hostingpackages/add_hosting_option.html'
|
||||
class AddHostingOption(LoginRequiredMixin, StaffuserRequiredMixin, FormView):
|
||||
template_name = "hostingpackages/add_hosting_option.html"
|
||||
|
||||
def get_form_class(self):
|
||||
optiontype = self.kwargs['type']
|
||||
if optiontype == 'diskspace':
|
||||
optiontype = self.kwargs["type"]
|
||||
if optiontype == "diskspace":
|
||||
return AddDiskspaceOptionForm
|
||||
elif optiontype == 'mailboxes':
|
||||
elif optiontype == "mailboxes":
|
||||
return AddMailboxOptionForm
|
||||
elif optiontype == 'databases':
|
||||
elif optiontype == "databases":
|
||||
return AddUserDatabaseOptionForm
|
||||
raise Http404()
|
||||
|
||||
def get_hosting_package(self):
|
||||
return get_object_or_404(
|
||||
CustomerHostingPackage, pk=int(self.kwargs['package']))
|
||||
return get_object_or_404(CustomerHostingPackage, pk=int(self.kwargs["package"]))
|
||||
|
||||
def get_option_template(self):
|
||||
optiontype = self.kwargs['type']
|
||||
optionid = int(self.kwargs['optionid'])
|
||||
if optiontype == 'diskspace':
|
||||
optiontype = self.kwargs["type"]
|
||||
optionid = int(self.kwargs["optionid"])
|
||||
if optiontype == "diskspace":
|
||||
return get_object_or_404(DiskSpaceOption, pk=optionid)
|
||||
elif optiontype == 'mailboxes':
|
||||
elif optiontype == "mailboxes":
|
||||
return get_object_or_404(MailboxOption, pk=optionid)
|
||||
elif optiontype == 'databases':
|
||||
elif optiontype == "databases":
|
||||
return get_object_or_404(UserDatabaseOption, pk=optionid)
|
||||
raise Http404()
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AddHostingOption, self).get_form_kwargs()
|
||||
kwargs['hostingpackage'] = self.get_hosting_package()
|
||||
kwargs['option_template'] = self.get_option_template()
|
||||
kwargs["hostingpackage"] = self.get_hosting_package()
|
||||
kwargs["option_template"] = self.get_option_template()
|
||||
return kwargs
|
||||
|
||||
def get_initial(self):
|
||||
initial = super(AddHostingOption, self).get_initial()
|
||||
template = self.get_option_template()
|
||||
if type(template) == DiskSpaceOption:
|
||||
initial.update({
|
||||
'diskspace': template.diskspace,
|
||||
'diskspace_unit': template.diskspace_unit,
|
||||
})
|
||||
initial.update(
|
||||
{
|
||||
"diskspace": template.diskspace,
|
||||
"diskspace_unit": template.diskspace_unit,
|
||||
}
|
||||
)
|
||||
elif type(template) == MailboxOption:
|
||||
initial['number'] = template.number
|
||||
initial["number"] = template.number
|
||||
elif type(template) == UserDatabaseOption:
|
||||
initial['number'] = template.number
|
||||
initial["number"] = template.number
|
||||
else:
|
||||
raise Http404()
|
||||
return initial
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AddHostingOption, self).get_context_data(**kwargs)
|
||||
context['option_template'] = self.get_option_template()
|
||||
context["option_template"] = self.get_option_template()
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
|
@ -259,8 +266,8 @@ class AddHostingOption(
|
|||
hosting_package = self.get_hosting_package()
|
||||
messages.success(
|
||||
self.request,
|
||||
_("Successfully added option {option} to hosting package "
|
||||
"{package}.").format(
|
||||
option=option, package=hosting_package.name)
|
||||
_(
|
||||
"Successfully added option {option} to hosting package " "{package}."
|
||||
).format(option=option, package=hosting_package.name),
|
||||
)
|
||||
return redirect(hosting_package)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue