diff --git a/docs/changelog.rst b/docs/changelog.rst index d95fc2b..6585ac5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,10 @@ Changelog ========= +* :feature:`-` add hosting packages list for staff users +* :feature:`-` allow creation of new hosting packages for staff users without + the need to navigate to a customer dashboard first + * :release:`0.6.0 <2015-01-24>` * :feature:`-` add frontend functionality to set an os users' sftp password (needs gvaldap >= 0.4.0 on the LDAP side) diff --git a/gnuviechadmin/hostingpackages/forms.py b/gnuviechadmin/hostingpackages/forms.py index bc8a8d9..727580d 100644 --- a/gnuviechadmin/hostingpackages/forms.py +++ b/gnuviechadmin/hostingpackages/forms.py @@ -17,9 +17,10 @@ from crispy_forms.layout import ( from .models import CustomerHostingPackage -class CreateHostingPackageForm(forms.ModelForm): +class CreateCustomerHostingPackageForm(forms.ModelForm): """ - This form class is used for creating new customer hosting packages. + This form class is used for creating new customer hosting packages with + a preselected customer. """ class Meta: @@ -28,13 +29,13 @@ class CreateHostingPackageForm(forms.ModelForm): def __init__(self, instance, *args, **kwargs): username = kwargs.pop('user') - super(CreateHostingPackageForm, self).__init__( + super(CreateCustomerHostingPackageForm, self).__init__( *args, **kwargs ) self.fields['description'].widget.attrs['rows'] = 2 self.helper = FormHelper() self.helper.form_action = reverse( - 'create_hosting_package', kwargs={'user': username} + 'create_customer_hosting_package', kwargs={'user': username} ) self.helper.layout = Layout( 'template', @@ -42,3 +43,28 @@ class CreateHostingPackageForm(forms.ModelForm): 'description', Submit('submit', _('Add Hosting Package')), ) + + +class CreateHostingPackageForm(forms.ModelForm): + """ + This form class is used for creating new customer hosting packages. + + """ + class Meta: + model = CustomerHostingPackage + fields = ['customer', 'template', 'name', 'description'] + + def __init__(self, instance, *args, **kwargs): + super(CreateHostingPackageForm, self).__init__( + *args, **kwargs + ) + self.fields['description'].widget.attrs['rows'] = 2 + self.helper = FormHelper() + self.helper.form_action = reverse('create_hosting_package') + self.helper.layout = Layout( + 'customer', + 'template', + 'name', + 'description', + Submit('submit', _('Add Hosting Package')), + ) diff --git a/gnuviechadmin/hostingpackages/urls.py b/gnuviechadmin/hostingpackages/urls.py index 0280eca..d8709fd 100644 --- a/gnuviechadmin/hostingpackages/urls.py +++ b/gnuviechadmin/hostingpackages/urls.py @@ -7,16 +7,24 @@ from __future__ import absolute_import, unicode_literals from django.conf.urls import patterns, url from .views import ( + AllCustomerHostingPackageList, CreateHostingPackage, + CreateCustomerHostingPackage, CustomerHostingPackageDetails, ) urlpatterns = patterns( '', - url(r'^(?P[\w0-9@.+-_]+)/create$', CreateHostingPackage.as_view(), + url(r'^create$', CreateHostingPackage.as_view(), name='create_hosting_package'), + url(r'^(?P[\w0-9@.+-_]+)/create$', + CreateCustomerHostingPackage.as_view(), + name='create_customer_hosting_package'), url(r'^(?P[\w0-9@.+-_]+)/hostingpackage/(?P\d+)/$', CustomerHostingPackageDetails.as_view(), name='hosting_package_details'), + url(r'^allpackages/', + AllCustomerHostingPackageList.as_view(), + name='all_hosting_packages'), ) diff --git a/gnuviechadmin/hostingpackages/views.py b/gnuviechadmin/hostingpackages/views.py index e368088..7917b14 100644 --- a/gnuviechadmin/hostingpackages/views.py +++ b/gnuviechadmin/hostingpackages/views.py @@ -5,10 +5,12 @@ 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.shortcuts import redirect, get_object_or_404 from django.utils.translation import ugettext as _ -from django.views.generic import DetailView +from django.views.generic import ( + DetailView, + ListView, +) from django.views.generic.edit import CreateView from django.contrib import messages from django.contrib.auth import get_user_model @@ -20,7 +22,10 @@ from braces.views import ( from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin -from .forms import CreateHostingPackageForm +from .forms import ( + CreateCustomerHostingPackageForm, + CreateHostingPackageForm, +) from .models import CustomerHostingPackage @@ -36,23 +41,37 @@ class CreateHostingPackage( template_name_suffix = '_create' form_class = CreateHostingPackageForm + def form_valid(self, form): + hostingpackage = form.save() + messages.success( + self.request, + _('Started setup of new hosting package {name}.').format( + name=hostingpackage.name) + ) + return redirect(hostingpackage) + + +class CreateCustomerHostingPackage(CreateHostingPackage): + """ + Create a hosting package for a selected customer. + + """ + form_class = CreateCustomerHostingPackageForm + def get_form_kwargs(self): - kwargs = super(CreateHostingPackage, self).get_form_kwargs() + kwargs = super(CreateCustomerHostingPackage, 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']) + return get_object_or_404( + get_user_model(), username=self.kwargs['user']) def get_context_data(self, **kwargs): - context = super(CreateHostingPackage, self).get_context_data(**kwargs) + context = super(CreateCustomerHostingPackage, 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() @@ -62,7 +81,7 @@ class CreateHostingPackage( _('Started setup of new hosting package {name}.').format( name=hostingpackage.name) ) - return redirect(self.get_success_url()) + return redirect(hostingpackage) class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView): @@ -74,7 +93,8 @@ class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView): context_object_name = 'hostingpackage' def get_customer_object(self): - return get_user_model().objects.get(username=self.kwargs['user']) + return get_object_or_404( + get_user_model(), username=self.kwargs['user']) def get_context_data(self, **kwargs): context = super(CustomerHostingPackageDetails, self).get_context_data( @@ -84,3 +104,10 @@ class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView): 'uploadserver': settings.OSUSER_UPLOAD_SERVER, }) return context + + +class AllCustomerHostingPackageList( + LoginRequiredMixin, StaffuserRequiredMixin, ListView +): + model = CustomerHostingPackage + template_name_suffix = '_admin_list' diff --git a/gnuviechadmin/templates/base.html b/gnuviechadmin/templates/base.html index 4d5cc0f..f32143c 100644 --- a/gnuviechadmin/templates/base.html +++ b/gnuviechadmin/templates/base.html @@ -45,7 +45,10 @@ diff --git a/gnuviechadmin/templates/hostingpackages/customerhostingpackage_admin_list.html b/gnuviechadmin/templates/hostingpackages/customerhostingpackage_admin_list.html new file mode 100644 index 0000000..73623b1 --- /dev/null +++ b/gnuviechadmin/templates/hostingpackages/customerhostingpackage_admin_list.html @@ -0,0 +1,32 @@ +{% extends "hostingpackages/base.html" %} +{% load i18n %} +{% block title %}{{ block.super }} - {% trans "All hosting packages" %}{% endblock title %} +{% block page_title %}{% trans "All hosting packages" %}{% endblock page_title %} + +{% block content %} +{% if customerhostingpackage_list %} + + + + + + + + + + {% for package in customerhostingpackage_list %} + + + + + + {% endfor %} + +
{% trans "Name" %}{% trans "Customer" %}{% trans "Setup date" %}
{{ package.name }}{{ package.customer }}{{ package.created }}
+{% else %} +

{% trans "There are no hosting packages setup yet." %}

+{% endif %} +

+{% trans "Add hosting package" %} +

+{% endblock content %}