86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
"""
|
|
This module defines views related to hosting packages.
|
|
|
|
"""
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
from django.conf import settings
|
|
from django.core.urlresolvers import reverse
|
|
from django.shortcuts import redirect
|
|
from django.utils.translation import ugettext as _
|
|
from django.views.generic import DetailView
|
|
from django.views.generic.edit import CreateView
|
|
from django.contrib import messages
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from braces.views import (
|
|
LoginRequiredMixin,
|
|
StaffuserRequiredMixin,
|
|
)
|
|
|
|
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
|
|
|
from .forms import CreateHostingPackageForm
|
|
from .models import CustomerHostingPackage
|
|
|
|
|
|
class CreateHostingPackage(
|
|
LoginRequiredMixin, StaffuserRequiredMixin, CreateView
|
|
):
|
|
"""
|
|
Create a hosting package.
|
|
|
|
"""
|
|
model = CustomerHostingPackage
|
|
raise_exception = True
|
|
template_name_suffix = '_create'
|
|
form_class = CreateHostingPackageForm
|
|
|
|
def get_form_kwargs(self):
|
|
kwargs = super(CreateHostingPackage, self).get_form_kwargs()
|
|
kwargs.update(self.kwargs)
|
|
return kwargs
|
|
|
|
def get_customer_object(self):
|
|
return get_user_model().objects.get(username=self.kwargs['user'])
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(CreateHostingPackage, self).get_context_data(**kwargs)
|
|
context['customer'] = self.get_customer_object()
|
|
return context
|
|
|
|
def get_success_url(self):
|
|
return reverse(
|
|
'customer_dashboard', kwargs={'slug': self.kwargs['user']})
|
|
|
|
def form_valid(self, form):
|
|
hostingpackage = form.save(commit=False)
|
|
hostingpackage.customer = self.get_customer_object()
|
|
hostingpackage.save()
|
|
messages.success(
|
|
self.request,
|
|
_('Started setup of new hosting package {name}.').format(
|
|
name=hostingpackage.name)
|
|
)
|
|
return redirect(self.get_success_url())
|
|
|
|
|
|
class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView):
|
|
"""
|
|
This view is for showing details of a customer hosting package.
|
|
|
|
"""
|
|
model = CustomerHostingPackage
|
|
context_object_name = 'hostingpackage'
|
|
|
|
def get_customer_object(self):
|
|
return get_user_model().objects.get(username=self.kwargs['user'])
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(CustomerHostingPackageDetails, self).get_context_data(
|
|
**kwargs)
|
|
context.update({
|
|
'customer': self.get_customer_object(),
|
|
'uploadserver': settings.OSUSER_UPLOAD_SERVER,
|
|
})
|
|
return context
|