Add hosting plans and account assignment
Manage hosting plans in the panel and allow authorized operators to assign them to hosting accounts.
This commit is contained in:
1 parent
e59ee72940
commit
bb95b86173
13 files changed
+346
-15
No files matched your search
@@ -2,16 +2,18 @@ from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.views import View
|
||||
from django.views.generic import CreateView, DetailView, ListView, UpdateView
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
|
||||
from .models import HostingAccount, WebProvisioningPlan
|
||||
from .models import HostingAccount, HostingPlan, WebProvisioningPlan
|
||||
from .web_node import build_web_smoke_bundle, serialize_deployment_manifest
|
||||
|
||||
VIEW_ACCOUNTS = "hosting.view_hostingaccount"
|
||||
CHANGE_ACCOUNTS = "hosting.change_hostingaccount"
|
||||
VIEW_PLANS = "hosting.view_webprovisioningplan"
|
||||
VIEW_HOSTING_PLANS = "hosting.view_hostingplan"
|
||||
|
||||
|
||||
class AccountList(PermissionRequiredMixin, ListView):
|
||||
@@ -23,7 +25,9 @@ class AccountList(PermissionRequiredMixin, ListView):
|
||||
|
||||
def get_queryset(self):
|
||||
self.search = self.request.GET.get("q", "").strip()[:253]
|
||||
accounts = HostingAccount.objects.order_by("primary_domain")
|
||||
accounts = HostingAccount.objects.select_related("hosting_plan").order_by(
|
||||
"primary_domain"
|
||||
)
|
||||
if self.search:
|
||||
accounts = accounts.filter(
|
||||
Q(name__icontains=self.search)
|
||||
@@ -35,28 +39,44 @@ class AccountList(PermissionRequiredMixin, ListView):
|
||||
return super().get_context_data(search=self.search, **kwargs)
|
||||
|
||||
|
||||
class AccountCreate(PermissionRequiredMixin, CreateView):
|
||||
class AccountEditor:
|
||||
model = HostingAccount
|
||||
permission_required = (VIEW_ACCOUNTS, "hosting.add_hostingaccount")
|
||||
template_name = "hosting/account_form.html"
|
||||
fields = ("name", "primary_domain")
|
||||
|
||||
def get_form_class(self):
|
||||
self.fields = ("name", "primary_domain")
|
||||
if self.request.user.has_perm(VIEW_HOSTING_PLANS):
|
||||
self.fields += ("hosting_plan",)
|
||||
return super().get_form_class()
|
||||
|
||||
def get_form(self, form_class=None):
|
||||
form = super().get_form(form_class)
|
||||
if "hosting_plan" in form.fields:
|
||||
form.fields["hosting_plan"].empty_label = "Unassigned"
|
||||
return form
|
||||
|
||||
|
||||
class AccountCreate(PermissionRequiredMixin, AccountEditor, CreateView):
|
||||
permission_required = (VIEW_ACCOUNTS, "hosting.add_hostingaccount")
|
||||
extra_context = {"page_title": "Add hosting account", "submit_label": "Add account"}
|
||||
|
||||
|
||||
class AccountEdit(PermissionRequiredMixin, UpdateView):
|
||||
model = HostingAccount
|
||||
class AccountEdit(PermissionRequiredMixin, AccountEditor, UpdateView):
|
||||
permission_required = (VIEW_ACCOUNTS, CHANGE_ACCOUNTS)
|
||||
template_name = "hosting/account_form.html"
|
||||
context_object_name = "account"
|
||||
fields = ("name", "primary_domain")
|
||||
extra_context = {
|
||||
"page_title": "Edit hosting account",
|
||||
"submit_label": "Save changes",
|
||||
}
|
||||
|
||||
def form_valid(self, form):
|
||||
self.object = form.save(commit=False)
|
||||
self.object.save(update_fields=form.changed_data)
|
||||
return redirect(self.object)
|
||||
|
||||
|
||||
class AccountDetail(PermissionRequiredMixin, DetailView):
|
||||
model = HostingAccount
|
||||
queryset = HostingAccount.objects.select_related("hosting_plan")
|
||||
permission_required = VIEW_ACCOUNTS
|
||||
template_name = "hosting/account_detail.html"
|
||||
context_object_name = "account"
|
||||
@@ -70,6 +90,31 @@ class AccountDetail(PermissionRequiredMixin, DetailView):
|
||||
return context
|
||||
|
||||
|
||||
class HostingPlanList(PermissionRequiredMixin, ListView):
|
||||
model = HostingPlan
|
||||
permission_required = VIEW_HOSTING_PLANS
|
||||
template_name = "hosting/hosting_plan_list.html"
|
||||
context_object_name = "hosting_plans"
|
||||
paginate_by = 20
|
||||
|
||||
|
||||
class HostingPlanEditor:
|
||||
model = HostingPlan
|
||||
fields = ("name", "description")
|
||||
template_name = "hosting/hosting_plan_form.html"
|
||||
success_url = reverse_lazy("panel:hosting_plans")
|
||||
|
||||
|
||||
class HostingPlanCreate(PermissionRequiredMixin, HostingPlanEditor, CreateView):
|
||||
permission_required = (VIEW_HOSTING_PLANS, "hosting.add_hostingplan")
|
||||
extra_context = {"page_title": "Add hosting plan", "submit_label": "Add plan"}
|
||||
|
||||
|
||||
class HostingPlanEdit(PermissionRequiredMixin, HostingPlanEditor, UpdateView):
|
||||
permission_required = (VIEW_HOSTING_PLANS, "hosting.change_hostingplan")
|
||||
extra_context = {"page_title": "Edit hosting plan", "submit_label": "Save changes"}
|
||||
|
||||
|
||||
class RequestWebPlan(PermissionRequiredMixin, SingleObjectMixin, View):
|
||||
model = HostingAccount
|
||||
permission_required = (VIEW_ACCOUNTS, CHANGE_ACCOUNTS, VIEW_PLANS)
|
||||
|
||||
Reference in new issue
Block a user