Add new hostingpackages app
- implement models for hosting packages, hosting options and customer specific variants - implement admin interface - add documentation
This commit is contained in:
parent
3870bcf483
commit
9f63fbbb5d
13 changed files with 1158 additions and 0 deletions
121
gnuviechadmin/hostingpackages/admin.py
Normal file
121
gnuviechadmin/hostingpackages/admin.py
Normal file
|
@ -0,0 +1,121 @@
|
|||
"""
|
||||
This module contains the admin site interface for hosting packages.
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django import forms
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import (
|
||||
CustomerHostingPackage,
|
||||
CustomerDiskSpaceOption,
|
||||
CustomerUserDatabaseOption,
|
||||
CustomerMailboxOption,
|
||||
DiskSpaceOption,
|
||||
HostingPackageTemplate,
|
||||
MailboxOption,
|
||||
UserDatabaseOption,
|
||||
)
|
||||
|
||||
|
||||
class CustomerHostingPackageCreateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = CustomerHostingPackage
|
||||
fields = ['customer', 'template', 'name']
|
||||
|
||||
def save(self, **kwargs):
|
||||
"""
|
||||
Save the customer hosting package.
|
||||
|
||||
:param kwargs: keyword arguments passed to create method
|
||||
:return: customer hosting package instance
|
||||
:rtype: :py:class:`hostingpackages.models.CustomerHostingPackage`
|
||||
|
||||
"""
|
||||
hostinpackages = CustomerHostingPackage.objects.create_from_template(
|
||||
customer=self.cleaned_data['customer'],
|
||||
template=self.cleaned_data['template'],
|
||||
name=self.cleaned_data['name'],
|
||||
**kwargs)
|
||||
return hostinpackages
|
||||
|
||||
def save_m2m(self):
|
||||
pass
|
||||
|
||||
|
||||
class CustomerDiskSpaceOptionInline(admin.TabularInline):
|
||||
model = CustomerDiskSpaceOption
|
||||
extra = 0
|
||||
|
||||
|
||||
class CustomerMailboxOptionInline(admin.TabularInline):
|
||||
model = CustomerMailboxOption
|
||||
extra = 0
|
||||
|
||||
|
||||
class CustomerUserDatabaseOptionInline(admin.TabularInline):
|
||||
model = CustomerUserDatabaseOption
|
||||
extra = 0
|
||||
|
||||
|
||||
class CustomerHostingPackageAdmin(admin.ModelAdmin):
|
||||
add_form = CustomerHostingPackageCreateForm
|
||||
add_fieldsets = (
|
||||
(None, {
|
||||
'fields': ('customer', 'template', 'name')
|
||||
}),
|
||||
)
|
||||
|
||||
inlines = [
|
||||
CustomerDiskSpaceOptionInline,
|
||||
CustomerMailboxOptionInline,
|
||||
CustomerUserDatabaseOptionInline,
|
||||
]
|
||||
|
||||
def get_form(self, request, obj=None, **kwargs):
|
||||
"""
|
||||
Use special form for customer hosting package creation.
|
||||
|
||||
:param request: the current HTTP request
|
||||
:param obj: either a :py:class:`CustomerHostingPackage
|
||||
<hostingpackages.models.CustomerHostingPackage>` instance or None
|
||||
for a new customer hosting package
|
||||
:param kwargs: keyword arguments to be passed to
|
||||
:py:meth:`django.contrib.admin.ModelAdmin.get_form`
|
||||
:return: form instance
|
||||
|
||||
"""
|
||||
defaults = {}
|
||||
if obj is None:
|
||||
defaults.update({
|
||||
'form': self.add_form,
|
||||
'fields': admin.options.flatten_fieldsets(self.add_fieldsets),
|
||||
})
|
||||
defaults.update(kwargs)
|
||||
return super(CustomerHostingPackageAdmin, self).get_form(
|
||||
request, obj, **defaults)
|
||||
|
||||
def get_readonly_fields(self, request, obj=None):
|
||||
"""
|
||||
Make sure that customer and template are not editable for existing
|
||||
customer hosting packages.
|
||||
|
||||
:param request: the current HTTP request
|
||||
:param obj: either a :py:class:`CustomerHostingPackage
|
||||
<hostingpackages.models.CustomerHostingPackage>` instance or None
|
||||
for a new customer hosting package
|
||||
:return: a list of fields
|
||||
:rtype: list
|
||||
|
||||
"""
|
||||
if obj:
|
||||
return ['customer', 'template']
|
||||
return []
|
||||
|
||||
|
||||
admin.site.register(CustomerHostingPackage, CustomerHostingPackageAdmin)
|
||||
admin.site.register(DiskSpaceOption)
|
||||
admin.site.register(HostingPackageTemplate)
|
||||
admin.site.register(MailboxOption)
|
||||
admin.site.register(UserDatabaseOption)
|
Loading…
Add table
Add a link
Reference in a new issue