implement adding websites
- implement websites.models.Website - add migration - implement websites.views.AddWebsite - implement websites.forms.AddWebsiteForm - define URL pattern 'add_website' in websites.urls - register Website model in websites.admin - add templates websites/base.html and websites/website_create.html - add german translation for new strings - add website URLs to gnuviechadmin.urls - add websites to INSTALLED_APPS - add changelog entry
This commit is contained in:
parent
cff35dd408
commit
711a96212c
12 changed files with 297 additions and 5 deletions
|
@ -1,3 +1,60 @@
|
|||
from django.shortcuts import render
|
||||
"""
|
||||
This module defines views for website handling.
|
||||
|
||||
# Create your views here.
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic.edit import (
|
||||
CreateView,
|
||||
)
|
||||
from django.contrib import messages
|
||||
|
||||
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
||||
from gvawebcore.views import HostingPackageAndCustomerMixin
|
||||
|
||||
from domains.models import HostingDomain
|
||||
from .forms import AddWebsiteForm
|
||||
from .models import Website
|
||||
|
||||
|
||||
class AddWebsite(
|
||||
HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, CreateView
|
||||
):
|
||||
"""
|
||||
This view is used to setup new websites for a customer hosting package.
|
||||
|
||||
"""
|
||||
model = Website
|
||||
context_object_name = 'website'
|
||||
template_name_suffix = '_create'
|
||||
form_class = AddWebsiteForm
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AddWebsite, self).get_form_kwargs()
|
||||
kwargs.update({
|
||||
'hostingpackage': self.get_hosting_package(),
|
||||
'domain': get_object_or_404(
|
||||
HostingDomain, domain=self.kwargs['domain']),
|
||||
})
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AddWebsite, self).get_context_data(**kwargs)
|
||||
context.update({
|
||||
'customer': self.get_customer_object(),
|
||||
'domain': get_object_or_404(
|
||||
HostingDomain, domain=self.kwargs['domain'])
|
||||
})
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
website = form.save()
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Successfully added website {subdomain}.{domain}').format(
|
||||
subdomain=website.subdomain, domain=website.domain.domain
|
||||
)
|
||||
)
|
||||
return redirect(self.get_hosting_package())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue