Merge branch 'feature/admin_customer_list' into feature/customer_domains
* feature/admin_customer_list: update changelog to mention the new feature add link hosting package list templates add new views to hostingpackages app
This commit is contained in:
commit
110b3d03f2
7 changed files with 120 additions and 20 deletions
|
@ -1,6 +1,10 @@
|
||||||
Changelog
|
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>`
|
* :release:`0.6.0 <2015-01-24>`
|
||||||
* :feature:`-` add frontend functionality to set an os users' sftp password
|
* :feature:`-` add frontend functionality to set an os users' sftp password
|
||||||
(needs gvaldap >= 0.4.0 on the LDAP side)
|
(needs gvaldap >= 0.4.0 on the LDAP side)
|
||||||
|
|
|
@ -17,9 +17,10 @@ from crispy_forms.layout import (
|
||||||
from .models import CustomerHostingPackage
|
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:
|
class Meta:
|
||||||
|
@ -28,13 +29,13 @@ class CreateHostingPackageForm(forms.ModelForm):
|
||||||
|
|
||||||
def __init__(self, instance, *args, **kwargs):
|
def __init__(self, instance, *args, **kwargs):
|
||||||
username = kwargs.pop('user')
|
username = kwargs.pop('user')
|
||||||
super(CreateHostingPackageForm, self).__init__(
|
super(CreateCustomerHostingPackageForm, self).__init__(
|
||||||
*args, **kwargs
|
*args, **kwargs
|
||||||
)
|
)
|
||||||
self.fields['description'].widget.attrs['rows'] = 2
|
self.fields['description'].widget.attrs['rows'] = 2
|
||||||
self.helper = FormHelper()
|
self.helper = FormHelper()
|
||||||
self.helper.form_action = reverse(
|
self.helper.form_action = reverse(
|
||||||
'create_hosting_package', kwargs={'user': username}
|
'create_customer_hosting_package', kwargs={'user': username}
|
||||||
)
|
)
|
||||||
self.helper.layout = Layout(
|
self.helper.layout = Layout(
|
||||||
'template',
|
'template',
|
||||||
|
@ -42,3 +43,28 @@ class CreateHostingPackageForm(forms.ModelForm):
|
||||||
'description',
|
'description',
|
||||||
Submit('submit', _('Add Hosting Package')),
|
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')),
|
||||||
|
)
|
||||||
|
|
|
@ -7,16 +7,24 @@ from __future__ import absolute_import, unicode_literals
|
||||||
from django.conf.urls import patterns, url
|
from django.conf.urls import patterns, url
|
||||||
|
|
||||||
from .views import (
|
from .views import (
|
||||||
|
AllCustomerHostingPackageList,
|
||||||
CreateHostingPackage,
|
CreateHostingPackage,
|
||||||
|
CreateCustomerHostingPackage,
|
||||||
CustomerHostingPackageDetails,
|
CustomerHostingPackageDetails,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
url(r'^(?P<user>[\w0-9@.+-_]+)/create$', CreateHostingPackage.as_view(),
|
url(r'^create$', CreateHostingPackage.as_view(),
|
||||||
name='create_hosting_package'),
|
name='create_hosting_package'),
|
||||||
|
url(r'^(?P<user>[\w0-9@.+-_]+)/create$',
|
||||||
|
CreateCustomerHostingPackage.as_view(),
|
||||||
|
name='create_customer_hosting_package'),
|
||||||
url(r'^(?P<user>[\w0-9@.+-_]+)/hostingpackage/(?P<pk>\d+)/$',
|
url(r'^(?P<user>[\w0-9@.+-_]+)/hostingpackage/(?P<pk>\d+)/$',
|
||||||
CustomerHostingPackageDetails.as_view(),
|
CustomerHostingPackageDetails.as_view(),
|
||||||
name='hosting_package_details'),
|
name='hosting_package_details'),
|
||||||
|
url(r'^allpackages/',
|
||||||
|
AllCustomerHostingPackageList.as_view(),
|
||||||
|
name='all_hosting_packages'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,10 +5,12 @@ This module defines views related to hosting packages.
|
||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.urlresolvers import reverse
|
from django.shortcuts import redirect, get_object_or_404
|
||||||
from django.shortcuts import redirect
|
|
||||||
from django.utils.translation import ugettext as _
|
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.views.generic.edit import CreateView
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
@ -20,7 +22,10 @@ from braces.views import (
|
||||||
|
|
||||||
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
||||||
|
|
||||||
from .forms import CreateHostingPackageForm
|
from .forms import (
|
||||||
|
CreateCustomerHostingPackageForm,
|
||||||
|
CreateHostingPackageForm,
|
||||||
|
)
|
||||||
from .models import CustomerHostingPackage
|
from .models import CustomerHostingPackage
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,23 +41,37 @@ class CreateHostingPackage(
|
||||||
template_name_suffix = '_create'
|
template_name_suffix = '_create'
|
||||||
form_class = CreateHostingPackageForm
|
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):
|
def get_form_kwargs(self):
|
||||||
kwargs = super(CreateHostingPackage, self).get_form_kwargs()
|
kwargs = super(CreateCustomerHostingPackage, self).get_form_kwargs()
|
||||||
kwargs.update(self.kwargs)
|
kwargs.update(self.kwargs)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def get_customer_object(self):
|
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):
|
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()
|
context['customer'] = self.get_customer_object()
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_success_url(self):
|
|
||||||
return reverse(
|
|
||||||
'customer_dashboard', kwargs={'slug': self.kwargs['user']})
|
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
hostingpackage = form.save(commit=False)
|
hostingpackage = form.save(commit=False)
|
||||||
hostingpackage.customer = self.get_customer_object()
|
hostingpackage.customer = self.get_customer_object()
|
||||||
|
@ -62,7 +81,7 @@ class CreateHostingPackage(
|
||||||
_('Started setup of new hosting package {name}.').format(
|
_('Started setup of new hosting package {name}.').format(
|
||||||
name=hostingpackage.name)
|
name=hostingpackage.name)
|
||||||
)
|
)
|
||||||
return redirect(self.get_success_url())
|
return redirect(hostingpackage)
|
||||||
|
|
||||||
|
|
||||||
class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView):
|
class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView):
|
||||||
|
@ -74,7 +93,8 @@ class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView):
|
||||||
context_object_name = 'hostingpackage'
|
context_object_name = 'hostingpackage'
|
||||||
|
|
||||||
def get_customer_object(self):
|
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):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(CustomerHostingPackageDetails, self).get_context_data(
|
context = super(CustomerHostingPackageDetails, self).get_context_data(
|
||||||
|
@ -84,3 +104,10 @@ class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView):
|
||||||
'uploadserver': settings.OSUSER_UPLOAD_SERVER,
|
'uploadserver': settings.OSUSER_UPLOAD_SERVER,
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class AllCustomerHostingPackageList(
|
||||||
|
LoginRequiredMixin, StaffuserRequiredMixin, ListView
|
||||||
|
):
|
||||||
|
model = CustomerHostingPackage
|
||||||
|
template_name_suffix = '_admin_list'
|
||||||
|
|
|
@ -45,7 +45,10 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="collapse navbar-collapse">
|
<div class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li class="active"><a href="{% if user.is_authenticated %}{% url 'customer_dashboard' slug=user.username %}{% else %}{% url 'dashboard' %}{% endif %}">Home</a></li>
|
<li class="active"><a href="{% if user.is_authenticated %}{% url 'customer_dashboard' slug=user.username %}{% else %}{% url 'dashboard' %}{% endif %}">{% trans "Dashboard" %}</a></li>
|
||||||
|
{% if user.is_staff %}
|
||||||
|
<li><a href="{% url 'all_hosting_packages' %}">{% trans "All hosting packages" %}</a></li>
|
||||||
|
{% endif %}
|
||||||
<li><a href="#about">About</a></li>
|
<li><a href="#about">About</a></li>
|
||||||
<li><a href="#contact">Contact</a></li>
|
<li><a href="#contact">Contact</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
<p class="text-info">{% if user == object %}{% trans "You have no hosting packages yet." %}{% else %}{% trans "This user has no hosting packages assigned yet." %}{% endif %}</p>
|
<p class="text-info">{% if user == object %}{% trans "You have no hosting packages yet." %}{% else %}{% trans "This user has no hosting packages assigned yet." %}{% endif %}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if user.is_staff %}
|
{% if user.is_staff %}
|
||||||
<a href="{% url "create_hosting_package" user=object.username %}" class="btn btn-primary">{% trans "Add hosting package" %}</a>
|
<a href="{% url "create_customer_hosting_package" user=object.username %}" class="btn btn-primary">{% trans "Add hosting package" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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 %}
|
||||||
|
<table class="table table-condensed">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans "Name" %}</th>
|
||||||
|
<th>{% trans "Customer" %}</th>
|
||||||
|
<th>{% trans "Setup date" %}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for package in customerhostingpackage_list %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="{{ package.get_absolute_url }}">{{ package.name }}</a></td>
|
||||||
|
<td><a href="{% url 'customer_dashboard' slug=package.customer.username %}">{{ package.customer }}</a></td>
|
||||||
|
<td>{{ package.created }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<p class="text-info">{% trans "There are no hosting packages setup yet." %}</p>
|
||||||
|
{% endif %}
|
||||||
|
<p>
|
||||||
|
<a href="{% url 'create_hosting_package' %}" class="btn btn-primary">{% trans "Add hosting package" %}</a>
|
||||||
|
</p>
|
||||||
|
{% endblock content %}
|
Loading…
Reference in a new issue