2015-01-26 22:47:49 +01:00
|
|
|
"""
|
|
|
|
This module defines views for website handling.
|
2015-01-26 21:00:52 +01:00
|
|
|
|
2015-01-26 22:47:49 +01:00
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
from __future__ import absolute_import
|
2015-01-26 22:47:49 +01:00
|
|
|
|
|
|
|
from django.contrib import messages
|
2023-02-18 22:46:48 +01:00
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
|
|
|
from django.utils.translation import gettext as _
|
|
|
|
from django.views.generic.edit import CreateView, DeleteView
|
2015-01-26 22:47:49 +01:00
|
|
|
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
|
|
|
|
|
|
|
from domains.models import HostingDomain
|
2023-02-18 22:46:48 +01:00
|
|
|
from gvawebcore.views import HostingPackageAndCustomerMixin
|
|
|
|
|
2015-01-26 22:47:49 +01:00
|
|
|
from .forms import AddWebsiteForm
|
|
|
|
from .models import Website
|
|
|
|
|
|
|
|
|
|
|
|
class AddWebsite(
|
|
|
|
HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, CreateView
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
This view is used to setup new websites for a customer hosting package.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
|
2015-01-26 22:47:49 +01:00
|
|
|
model = Website
|
2023-02-18 22:46:48 +01:00
|
|
|
context_object_name = "website"
|
|
|
|
template_name_suffix = "_create"
|
2015-01-26 22:47:49 +01:00
|
|
|
form_class = AddWebsiteForm
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super(AddWebsite, self).get_form_kwargs()
|
2023-02-18 22:46:48 +01:00
|
|
|
kwargs.update(
|
|
|
|
{
|
|
|
|
"hostingpackage": self.get_hosting_package(),
|
|
|
|
"domain": get_object_or_404(
|
|
|
|
HostingDomain, domain=self.kwargs["domain"]
|
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
2015-01-26 22:47:49 +01:00
|
|
|
return kwargs
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(AddWebsite, self).get_context_data(**kwargs)
|
2023-02-18 22:46:48 +01:00
|
|
|
context.update(
|
|
|
|
{
|
|
|
|
"customer": self.get_customer_object(),
|
|
|
|
"domain": get_object_or_404(
|
|
|
|
HostingDomain, domain=self.kwargs["domain"]
|
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
2015-01-26 22:47:49 +01:00
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
website = form.save()
|
|
|
|
messages.success(
|
|
|
|
self.request,
|
2023-02-18 22:46:48 +01:00
|
|
|
_("Successfully added website {subdomain}.{domain}").format(
|
2015-01-26 22:47:49 +01:00
|
|
|
subdomain=website.subdomain, domain=website.domain.domain
|
2023-02-18 22:46:48 +01:00
|
|
|
),
|
2015-01-26 22:47:49 +01:00
|
|
|
)
|
|
|
|
return redirect(self.get_hosting_package())
|
2015-01-27 16:26:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DeleteWebsite(
|
|
|
|
HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, DeleteView
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
This view is used to delete websites in a customer hosting package.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
|
|
|
|
context_object_name = "website"
|
2015-01-27 16:26:10 +01:00
|
|
|
model = Website
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(DeleteWebsite, self).get_context_data(**kwargs)
|
2023-02-18 22:46:48 +01:00
|
|
|
context.update(
|
|
|
|
{
|
|
|
|
"customer": self.get_customer_object(),
|
|
|
|
"hostingpackage": self.get_hosting_package(),
|
|
|
|
}
|
|
|
|
)
|
2015-01-27 16:26:10 +01:00
|
|
|
return context
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return self.get_hosting_package().get_absolute_url()
|