Jan Dittberner
8615394c2f
- implement domains.forms.CreateHostingDomainForm - implement domains.models.HostingDomainManager.create_for_hosting_package that takes care of creating the necessary database objects for hosting domains assigned to a hosting package
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""
|
|
This module defines form classes for domain editing.
|
|
|
|
"""
|
|
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 HostingDomain
|
|
|
|
|
|
class CreateHostingDomainForm(forms.ModelForm):
|
|
"""
|
|
This form is used to create new HostingDomain instances.
|
|
|
|
"""
|
|
class Meta:
|
|
model = HostingDomain
|
|
fields = ['domain']
|
|
|
|
def __init__(self, instance, *args, **kwargs):
|
|
self.hosting_package = kwargs.pop('hostingpackage')
|
|
super(CreateHostingDomainForm, self).__init__(*args, **kwargs)
|
|
self.helper = FormHelper()
|
|
self.helper.form_action = reverse(
|
|
'create_hosting_domain', kwargs={
|
|
'package': self.hosting_package.id
|
|
})
|
|
self.helper.layout = Layout(
|
|
'domain',
|
|
Submit('submit', _('Add Hosting Domain')),
|
|
)
|
|
|
|
def clean(self):
|
|
self.cleaned_data = super(CreateHostingDomainForm, self).clean()
|
|
self.cleaned_data['hosting_package'] = self.hosting_package
|
|
|
|
def save(self, commit=True):
|
|
return HostingDomain.objects.create_for_hosting_package(
|
|
commit=commit, **self.cleaned_data)
|
|
|
|
def save_m2m(self):
|
|
pass
|