2015-01-25 00:40:43 +01:00
|
|
|
"""
|
|
|
|
This module defines views related to domains.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
from __future__ import absolute_import
|
2015-01-25 00:40:43 +01:00
|
|
|
|
|
|
|
from django.contrib import messages
|
2023-04-14 19:16:58 +02:00
|
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
2019-01-30 21:27:25 +01:00
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
2023-02-18 22:46:48 +01:00
|
|
|
from django.utils.translation import gettext as _
|
2019-01-30 21:27:25 +01:00
|
|
|
from django.views.generic.edit import CreateView
|
2015-01-25 00:40:43 +01:00
|
|
|
|
|
|
|
from hostingpackages.models import CustomerHostingPackage
|
2023-02-18 22:46:48 +01:00
|
|
|
|
2015-01-25 00:40:43 +01:00
|
|
|
from .forms import CreateHostingDomainForm
|
|
|
|
from .models import HostingDomain
|
|
|
|
|
|
|
|
|
2023-04-14 19:16:58 +02:00
|
|
|
class CreateHostingDomain(PermissionRequiredMixin, CreateView):
|
2015-01-25 00:40:43 +01:00
|
|
|
"""
|
|
|
|
This view is used for creating a new HostingDomain instance for an existing
|
|
|
|
hosting package.
|
|
|
|
"""
|
2019-01-30 21:27:25 +01:00
|
|
|
|
2015-01-25 00:40:43 +01:00
|
|
|
model = HostingDomain
|
|
|
|
raise_exception = True
|
2023-04-14 19:16:58 +02:00
|
|
|
permission_required = 'domains.add_hostingdomain'
|
2019-01-30 21:27:25 +01:00
|
|
|
template_name_suffix = "_create"
|
2015-01-25 00:40:43 +01:00
|
|
|
form_class = CreateHostingDomainForm
|
|
|
|
|
|
|
|
def _get_hosting_package(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
return get_object_or_404(CustomerHostingPackage, pk=int(self.kwargs["package"]))
|
2015-01-25 00:40:43 +01:00
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super(CreateHostingDomain, self).get_form_kwargs()
|
2019-01-30 21:27:25 +01:00
|
|
|
kwargs["hostingpackage"] = self._get_hosting_package()
|
2015-01-25 00:40:43 +01:00
|
|
|
return kwargs
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(CreateHostingDomain, self).get_context_data(**kwargs)
|
|
|
|
hosting_package = self._get_hosting_package()
|
2019-01-30 21:27:25 +01:00
|
|
|
context.update(
|
|
|
|
{"hostingpackage": hosting_package, "customer": hosting_package.customer}
|
|
|
|
)
|
2015-01-25 00:40:43 +01:00
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
hostingdomain = form.save()
|
|
|
|
messages.success(
|
|
|
|
self.request,
|
2019-01-30 21:27:25 +01:00
|
|
|
_("Successfully created domain {domainname}").format(
|
|
|
|
domainname=hostingdomain.domain
|
|
|
|
),
|
2015-01-25 00:40:43 +01:00
|
|
|
)
|
|
|
|
return redirect(self._get_hosting_package())
|