2015-01-20 00:51:05 +01:00
|
|
|
"""
|
|
|
|
This module contains the form classes related to hosting packages.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
from __future__ import absolute_import
|
2015-01-20 00:51:05 +01:00
|
|
|
|
2023-02-18 22:46:48 +01:00
|
|
|
from crispy_forms.helper import FormHelper
|
|
|
|
from crispy_forms.layout import Layout, Submit
|
2015-01-20 00:51:05 +01:00
|
|
|
from django import forms
|
2018-11-19 23:28:40 +01:00
|
|
|
from django.urls import reverse
|
2023-02-18 22:46:48 +01:00
|
|
|
from django.utils.translation import gettext as _
|
2015-01-20 00:51:05 +01:00
|
|
|
|
2015-01-25 15:15:39 +01:00
|
|
|
from .models import (
|
|
|
|
CustomerDiskSpaceOption,
|
|
|
|
CustomerHostingPackage,
|
|
|
|
CustomerMailboxOption,
|
|
|
|
CustomerUserDatabaseOption,
|
|
|
|
)
|
2015-01-20 00:51:05 +01:00
|
|
|
|
|
|
|
|
2015-01-24 23:34:15 +01:00
|
|
|
class CreateCustomerHostingPackageForm(forms.ModelForm):
|
2015-01-20 00:51:05 +01:00
|
|
|
"""
|
2015-01-24 23:34:15 +01:00
|
|
|
This form class is used for creating new customer hosting packages with
|
|
|
|
a preselected customer.
|
2015-01-20 00:51:05 +01:00
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
|
2015-01-20 00:51:05 +01:00
|
|
|
class Meta:
|
|
|
|
model = CustomerHostingPackage
|
2023-02-18 22:46:48 +01:00
|
|
|
fields = ["template", "name", "description"]
|
2015-01-20 00:51:05 +01:00
|
|
|
|
|
|
|
def __init__(self, instance, *args, **kwargs):
|
2023-02-18 22:46:48 +01:00
|
|
|
username = kwargs.pop("user")
|
|
|
|
super(CreateCustomerHostingPackageForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields["description"].widget.attrs["rows"] = 2
|
2015-01-20 00:51:05 +01:00
|
|
|
self.helper = FormHelper()
|
|
|
|
self.helper.form_action = reverse(
|
2023-02-18 22:46:48 +01:00
|
|
|
"create_customer_hosting_package", kwargs={"user": username}
|
2015-01-20 00:51:05 +01:00
|
|
|
)
|
|
|
|
self.helper.layout = Layout(
|
2023-02-18 22:46:48 +01:00
|
|
|
"template",
|
|
|
|
"name",
|
|
|
|
"description",
|
|
|
|
Submit("submit", _("Add Hosting Package")),
|
2015-01-20 00:51:05 +01:00
|
|
|
)
|
2015-01-24 23:34:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class CreateHostingPackageForm(forms.ModelForm):
|
|
|
|
"""
|
|
|
|
This form class is used for creating new customer hosting packages.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
|
2015-01-24 23:34:15 +01:00
|
|
|
class Meta:
|
|
|
|
model = CustomerHostingPackage
|
2023-02-18 22:46:48 +01:00
|
|
|
fields = ["customer", "template", "name", "description"]
|
2015-01-24 23:34:15 +01:00
|
|
|
|
|
|
|
def __init__(self, instance, *args, **kwargs):
|
2023-02-18 22:46:48 +01:00
|
|
|
super(CreateHostingPackageForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields["description"].widget.attrs["rows"] = 2
|
2015-01-24 23:34:15 +01:00
|
|
|
self.helper = FormHelper()
|
2023-02-18 22:46:48 +01:00
|
|
|
self.helper.form_action = reverse("create_hosting_package")
|
2015-01-24 23:34:15 +01:00
|
|
|
self.helper.layout = Layout(
|
2023-02-18 22:46:48 +01:00
|
|
|
"customer",
|
|
|
|
"template",
|
|
|
|
"name",
|
|
|
|
"description",
|
|
|
|
Submit("submit", _("Add Hosting Package")),
|
2015-01-24 23:34:15 +01:00
|
|
|
)
|
2015-01-25 15:15:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
class AddDiskspaceOptionForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = CustomerDiskSpaceOption
|
2023-02-18 22:46:48 +01:00
|
|
|
fields = ["diskspace", "diskspace_unit"]
|
2015-01-25 15:15:39 +01:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2023-02-18 22:46:48 +01:00
|
|
|
self.hostingpackage = kwargs.pop("hostingpackage")
|
|
|
|
self.option_template = kwargs.pop("option_template")
|
2015-01-25 15:15:39 +01:00
|
|
|
super(AddDiskspaceOptionForm, self).__init__(*args, **kwargs)
|
|
|
|
self.helper = FormHelper()
|
|
|
|
self.helper.form_action = reverse(
|
2023-02-18 22:46:48 +01:00
|
|
|
"add_hosting_option",
|
2015-01-25 15:15:39 +01:00
|
|
|
kwargs={
|
2023-02-18 22:46:48 +01:00
|
|
|
"package": self.hostingpackage.id,
|
|
|
|
"type": "diskspace",
|
|
|
|
"optionid": self.option_template.id,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.helper.add_input(Submit("submit", _("Add disk space option")))
|
2015-01-25 15:15:39 +01:00
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
self.instance.hosting_package = self.hostingpackage
|
|
|
|
self.instance.template = self.option_template
|
|
|
|
return super(AddDiskspaceOptionForm, self).save(commit=True)
|
|
|
|
|
|
|
|
|
|
|
|
class AddMailboxOptionForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = CustomerMailboxOption
|
2023-02-18 22:46:48 +01:00
|
|
|
fields = ["number"]
|
2015-01-25 15:15:39 +01:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2023-02-18 22:46:48 +01:00
|
|
|
self.hostingpackage = kwargs.pop("hostingpackage")
|
|
|
|
self.option_template = kwargs.pop("option_template")
|
2015-01-25 15:15:39 +01:00
|
|
|
super(AddMailboxOptionForm, self).__init__(*args, **kwargs)
|
|
|
|
self.helper = FormHelper()
|
|
|
|
self.helper.form_action = reverse(
|
2023-02-18 22:46:48 +01:00
|
|
|
"add_hosting_option",
|
2015-01-25 15:15:39 +01:00
|
|
|
kwargs={
|
2023-02-18 22:46:48 +01:00
|
|
|
"package": self.hostingpackage.id,
|
|
|
|
"type": "mailboxes",
|
|
|
|
"optionid": self.option_template.id,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.helper.add_input(Submit("submit", _("Add mailbox option")))
|
2015-01-25 15:15:39 +01:00
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
self.instance.hosting_package = self.hostingpackage
|
|
|
|
self.instance.template = self.option_template
|
|
|
|
return super(AddMailboxOptionForm, self).save(commit=True)
|
|
|
|
|
|
|
|
|
|
|
|
class AddUserDatabaseOptionForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = CustomerUserDatabaseOption
|
2023-02-18 22:46:48 +01:00
|
|
|
fields = ["number"]
|
2015-01-25 15:15:39 +01:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2023-02-18 22:46:48 +01:00
|
|
|
self.hostingpackage = kwargs.pop("hostingpackage")
|
|
|
|
self.option_template = kwargs.pop("option_template")
|
2015-01-25 15:15:39 +01:00
|
|
|
super(AddUserDatabaseOptionForm, self).__init__(*args, **kwargs)
|
|
|
|
self.helper = FormHelper()
|
|
|
|
self.helper.form_action = reverse(
|
2023-02-18 22:46:48 +01:00
|
|
|
"add_hosting_option",
|
2015-01-25 15:15:39 +01:00
|
|
|
kwargs={
|
2023-02-18 22:46:48 +01:00
|
|
|
"package": self.hostingpackage.id,
|
|
|
|
"type": "databases",
|
|
|
|
"optionid": self.option_template.id,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.helper.add_input(Submit("submit", _("Add database option")))
|
2015-01-25 15:15:39 +01:00
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
self.instance.hosting_package = self.hostingpackage
|
|
|
|
self.instance.template = self.option_template
|
|
|
|
self.instance.db_type = self.option_template.db_type
|
|
|
|
return super(AddUserDatabaseOptionForm, self).save(commit=True)
|