2015-01-20 00:51:05 +01:00
|
|
|
"""
|
|
|
|
This module contains the form classes related to hosting packages.
|
|
|
|
|
|
|
|
"""
|
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
|
|
|
|
from django import forms
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
|
|
from crispy_forms.helper import FormHelper
|
|
|
|
from crispy_forms.layout import (
|
|
|
|
Layout,
|
|
|
|
Submit,
|
|
|
|
)
|
|
|
|
|
|
|
|
from .models import CustomerHostingPackage
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = CustomerHostingPackage
|
|
|
|
fields = ['template', 'name', 'description']
|
|
|
|
|
|
|
|
def __init__(self, instance, *args, **kwargs):
|
|
|
|
username = kwargs.pop('user')
|
2015-01-24 23:34:15 +01:00
|
|
|
super(CreateCustomerHostingPackageForm, self).__init__(
|
2015-01-20 00:51:05 +01:00
|
|
|
*args, **kwargs
|
|
|
|
)
|
|
|
|
self.fields['description'].widget.attrs['rows'] = 2
|
|
|
|
self.helper = FormHelper()
|
|
|
|
self.helper.form_action = reverse(
|
2015-01-24 23:34:15 +01:00
|
|
|
'create_customer_hosting_package', kwargs={'user': username}
|
2015-01-20 00:51:05 +01:00
|
|
|
)
|
|
|
|
self.helper.layout = Layout(
|
|
|
|
'template',
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
Submit('submit', _('Add Hosting Package')),
|
|
|
|
)
|
2015-01-24 23:34:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class CreateHostingPackageForm(forms.ModelForm):
|
|
|
|
"""
|
|
|
|
This form class is used for creating new customer hosting packages.
|
|
|
|
|
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = CustomerHostingPackage
|
|
|
|
fields = ['customer', 'template', 'name', 'description']
|
|
|
|
|
|
|
|
def __init__(self, instance, *args, **kwargs):
|
|
|
|
super(CreateHostingPackageForm, self).__init__(
|
|
|
|
*args, **kwargs
|
|
|
|
)
|
|
|
|
self.fields['description'].widget.attrs['rows'] = 2
|
|
|
|
self.helper = FormHelper()
|
|
|
|
self.helper.form_action = reverse('create_hosting_package')
|
|
|
|
self.helper.layout = Layout(
|
|
|
|
'customer',
|
|
|
|
'template',
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
Submit('submit', _('Add Hosting Package')),
|
|
|
|
)
|