implement hosting domain creation
- implement domains.views.CreateHostingDomain - define new URL create_hosting_domain in domains.urls - add domains app URLs to gnuviechadmin.urls - add templates domains/base.html and domains/hostingdomain_create.html - link from hostingpackage detail page to domain creation view
This commit is contained in:
parent
8615394c2f
commit
1690cace4d
6 changed files with 96 additions and 1 deletions
16
gnuviechadmin/domains/urls.py
Normal file
16
gnuviechadmin/domains/urls.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
This module defines the URL patterns for domain related views.
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
from .views import CreateHostingDomain
|
||||
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
url(r'^(?P<package>\d+)/create$', CreateHostingDomain.as_view(),
|
||||
name='create_hosting_domain'),
|
||||
)
|
61
gnuviechadmin/domains/views.py
Normal file
61
gnuviechadmin/domains/views.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
"""
|
||||
This module defines views related to domains.
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.shortcuts import redirect, get_object_or_404
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.contrib import messages
|
||||
|
||||
from braces.views import (
|
||||
LoginRequiredMixin,
|
||||
StaffuserRequiredMixin,
|
||||
)
|
||||
|
||||
from hostingpackages.models import CustomerHostingPackage
|
||||
|
||||
from .forms import CreateHostingDomainForm
|
||||
from .models import HostingDomain
|
||||
|
||||
|
||||
class CreateHostingDomain(
|
||||
LoginRequiredMixin, StaffuserRequiredMixin, CreateView
|
||||
):
|
||||
"""
|
||||
This view is used for creating a new HostingDomain instance for an existing
|
||||
hosting package.
|
||||
|
||||
"""
|
||||
model = HostingDomain
|
||||
raise_exception = True
|
||||
template_name_suffix = '_create'
|
||||
form_class = CreateHostingDomainForm
|
||||
|
||||
def _get_hosting_package(self):
|
||||
return get_object_or_404(
|
||||
CustomerHostingPackage, pk=int(self.kwargs['package']))
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(CreateHostingDomain, self).get_form_kwargs()
|
||||
kwargs['hostingpackage'] = self._get_hosting_package()
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CreateHostingDomain, self).get_context_data(**kwargs)
|
||||
hosting_package = self._get_hosting_package()
|
||||
context.update({
|
||||
'hostingpackage': hosting_package,
|
||||
'customer': hosting_package.customer,
|
||||
})
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
hostingdomain = form.save()
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Successfully created domain {domainname}').format(
|
||||
domainname=hostingdomain.domain)
|
||||
)
|
||||
return redirect(self._get_hosting_package())
|
Loading…
Add table
Add a link
Reference in a new issue