From 1690cace4d1ac18e513d00f0766c92e084b8b962 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 25 Jan 2015 00:40:43 +0100 Subject: [PATCH] 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 --- gnuviechadmin/domains/urls.py | 16 +++++ gnuviechadmin/domains/views.py | 61 +++++++++++++++++++ gnuviechadmin/gnuviechadmin/urls.py | 1 + gnuviechadmin/templates/domains/base.html | 1 + .../domains/hostingdomain_create.html | 16 +++++ .../customerhostingpackage_detail.html | 2 +- 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 gnuviechadmin/domains/urls.py create mode 100644 gnuviechadmin/domains/views.py create mode 100644 gnuviechadmin/templates/domains/base.html create mode 100644 gnuviechadmin/templates/domains/hostingdomain_create.html diff --git a/gnuviechadmin/domains/urls.py b/gnuviechadmin/domains/urls.py new file mode 100644 index 0000000..d762b84 --- /dev/null +++ b/gnuviechadmin/domains/urls.py @@ -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\d+)/create$', CreateHostingDomain.as_view(), + name='create_hosting_domain'), +) diff --git a/gnuviechadmin/domains/views.py b/gnuviechadmin/domains/views.py new file mode 100644 index 0000000..2d16751 --- /dev/null +++ b/gnuviechadmin/domains/views.py @@ -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()) diff --git a/gnuviechadmin/gnuviechadmin/urls.py b/gnuviechadmin/gnuviechadmin/urls.py index d3356b0..ebc4157 100644 --- a/gnuviechadmin/gnuviechadmin/urls.py +++ b/gnuviechadmin/gnuviechadmin/urls.py @@ -10,6 +10,7 @@ urlpatterns = patterns( '', url(r'', include('dashboard.urls')), url(r'^accounts/', include('allauth.urls')), + url(r'^domains/', include('domains.urls')), url(r'^hosting/', include('hostingpackages.urls')), url(r'^osuser/', include('osusers.urls')), url(r'^admin/', include(admin.site.urls)), diff --git a/gnuviechadmin/templates/domains/base.html b/gnuviechadmin/templates/domains/base.html new file mode 100644 index 0000000..94d9808 --- /dev/null +++ b/gnuviechadmin/templates/domains/base.html @@ -0,0 +1 @@ +{% extends "base.html" %} diff --git a/gnuviechadmin/templates/domains/hostingdomain_create.html b/gnuviechadmin/templates/domains/hostingdomain_create.html new file mode 100644 index 0000000..d2ab6f8 --- /dev/null +++ b/gnuviechadmin/templates/domains/hostingdomain_create.html @@ -0,0 +1,16 @@ +{% extends "domains/base.html" %} +{% load i18n crispy_forms_tags %} +{% block title %}{{ block.super }} - {% blocktrans with package=hostingpackage.name full_name=customer.get_full_name %}Add Domain to Hosting Package {{ package }} of Customer {{ full_name }}{% endblocktrans %}{% endblock title %} +{% block page_title %}{% blocktrans with package=hostingpackage.name full_name=customer.get_full_name %}Add Domain to Hosting Package {{ package }} of Customer {{ full_name }}{% endblocktrans %}{% endblock page_title %} + +{% block content %} +{% crispy form %} +{% endblock content %} + +{% block extra_js %} + +{% endblock extra_js %} diff --git a/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html b/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html index 07728bd..43f0e2d 100644 --- a/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html +++ b/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html @@ -105,7 +105,7 @@

{% trans "There are no domains assigned to this hosting package yet." %}

{% endif %} {% if user.is_staff %} -

{% trans "Add domain" %}

+

{% trans "Add domain" %}

{% endif %}