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:
Jan Dittberner 2015-01-18 13:22:06 +01:00
parent 3870bcf483
commit 9f63fbbb5d
13 changed files with 1158 additions and 0 deletions

View file

@ -0,0 +1,5 @@
"""
This app takes care of hosting packages.
"""
default_app_config = 'hostingpackages.apps.HostingPackagesAppConfig'

View 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)

View file

@ -0,0 +1,18 @@
"""
This module contains the :py:class:`django.apps.AppConfig` instance for the
:py:mod:`hostingpackages` app.
"""
from __future__ import unicode_literals
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class HostingPackagesAppConfig(AppConfig):
"""
AppConfig for the :py:mod:`osusers` app.
"""
name = 'hostingpackages'
verbose_name = _('Hosting Packages and Options')

View file

@ -0,0 +1,192 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: gnuviechadmin hostingpackages\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-01-18 13:16+0100\n"
"PO-Revision-Date: 2015-01-18 13:17+0100\n"
"Last-Translator: Jan Dittberner <jan@dittberner.info>\n"
"Language-Team: Jan Dittberner <jan@dittberner.info>\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.6.10\n"
"X-Poedit-SourceCharset: UTF-8\n"
#: apps.py:17
msgid "Hosting Packages and Options"
msgstr "Hostingpakete und -Optionen"
#: models.py:20
msgid "MiB"
msgstr "MiB"
#: models.py:21
msgid "GiB"
msgstr "GiB"
#: models.py:22
msgid "TiB"
msgstr "TiB"
#: models.py:28
msgid "description"
msgstr "Beschreibung"
#: models.py:29
msgid "mailbox count"
msgstr "Anzahl Postfächer"
#: models.py:31 models.py:58
msgid "disk space"
msgstr "Speicherplatz"
#: models.py:31
msgid "disk space for the hosting package"
msgstr "Speicherplatz für das Hostingpaket"
#: models.py:33 models.py:60
msgid "unit of disk space"
msgstr "Maßeinheit für den Speicherplatz"
#: models.py:43 models.py:172
msgid "name"
msgstr "Name"
#: models.py:46
msgid "Hosting package"
msgstr "Hostingpaket"
#: models.py:47
msgid "Hosting packages"
msgstr "Hostingpakete"
#: models.py:66
msgid "Disk space option"
msgstr "Speicherplatzoption"
#: models.py:67
msgid "Disk space options"
msgstr "Speicherplatzoptionen"
#: models.py:70
#, python-brace-format
msgid "Additional disk space {space} {unit}"
msgstr "Zusätzlicher Speicherplatz {space} {unit}"
#: models.py:84
msgid "number of databases"
msgstr "Anzahl von Datenbanken"
#: models.py:86
msgid "database type"
msgstr "Datenbanktyp"
#: models.py:92
msgid "Database option"
msgstr "Datenbankoption"
#: models.py:93
msgid "Database options"
msgstr "Datenbankoptionen"
#: models.py:97
#, python-brace-format
msgid "{type} database"
msgid_plural "{count} {type} databases"
msgstr[0] "{type}-Datenbank"
msgstr[1] "{count} {type}-Datenbanken"
#: models.py:120
msgid "number of mailboxes"
msgstr "Anzahl von Postfächern"
#: models.py:125
msgid "Mailbox option"
msgstr "Postfachoption"
#: models.py:126
msgid "Mailbox options"
msgstr "Postfachoptionen"
#: models.py:130
#, python-brace-format
msgid "{count} additional mailbox"
msgid_plural "{count} additional mailboxes"
msgstr[0] "{count} zusätzliches Postfach"
msgstr[1] "{count} zusätzliche Postfächer"
#: models.py:165
msgid "customer"
msgstr "Kunde"
#: models.py:167
msgid "hosting package template"
msgstr "Hostingpaketvorlage"
#: models.py:169
msgid "The hosting package template that this hosting package is based on"
msgstr "Die Hostingpaketvorlage, auf der dieses Hostingpaket aufgebaut ist"
#: models.py:174
msgid "Operating system user"
msgstr "Betriebssystemnutzer"
#: models.py:181
msgid "customer hosting package"
msgstr "Kundenhostingpaket"
#: models.py:182
msgid "customer hosting packages"
msgstr "Kundenhostingpakete"
#: models.py:191
msgid "hosting package"
msgstr "Hostingpaket"
#: models.py:194
msgid "customer hosting option"
msgstr "kundenspezifische Hostingoption"
#: models.py:195
msgid "customer hosting options"
msgstr "kundenspezifische Hostingoptionen"
#: models.py:207
msgid "disk space option template"
msgstr "Speicherplatzoptionsvorlage"
#: models.py:209
msgid "The disk space option template that this disk space option is based on"
msgstr ""
"Die Speicherplatzoptionsvorlage auf der diese Speicherplatzoption aufgebaut "
"ist"
#: models.py:223
msgid "user database option template"
msgstr "Nutzerdatenbankoptionsvorlage"
#: models.py:225
msgid "The user database option template that this database option is based on"
msgstr ""
"Die Nutzerdatenbankoptionsvorlage auf der diese Datenbankoption aufgebaut ist"
#: models.py:239
msgid "mailbox option template"
msgstr "Postfachoptionsvorlage"
#: models.py:241
msgid "The mailbox option template that this mailbox option is based on"
msgstr "Die Postfachoptionsvorlage auf der diese Postfachoption aufgebaut ist"
#~ msgid "Hosting option"
#~ msgstr "Hostingoption"
#~ msgid "Hosting options"
#~ msgstr "Hostingoptionen"

View file

@ -0,0 +1,214 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.utils.timezone
from django.conf import settings
import model_utils.fields
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='CustomerHostingPackage',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('name', models.CharField(unique=True, max_length=128, verbose_name='name')),
('description', models.TextField(verbose_name='description', blank=True)),
('mailboxcount', models.PositiveIntegerField(verbose_name='mailbox count')),
('diskspace', models.PositiveIntegerField(help_text='disk space for the hosting package', verbose_name='disk space')),
('diskspace_unit', models.PositiveSmallIntegerField(verbose_name='unit of disk space', choices=[(0, 'MiB'), (1, 'GiB'), (2, 'TiB')])),
('customer', models.ForeignKey(verbose_name='customer', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'customer hosting package',
'verbose_name_plural': 'customer hosting packages',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='CustomerHostingPackageOption',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
],
options={
'verbose_name': 'customer hosting option',
'verbose_name_plural': 'customer hosting options',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='CustomerDiskSpaceOption',
fields=[
('customerhostingpackageoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.CustomerHostingPackageOption')),
('diskspace', models.PositiveIntegerField(verbose_name='disk space')),
('diskspace_unit', models.PositiveSmallIntegerField(verbose_name='unit of disk space', choices=[(0, 'MiB'), (1, 'GiB'), (2, 'TiB')])),
],
options={
'ordering': ['diskspace_unit', 'diskspace'],
'abstract': False,
'verbose_name': 'Disk space option',
'verbose_name_plural': 'Disk space options',
},
bases=('hostingpackages.customerhostingpackageoption', models.Model),
),
migrations.CreateModel(
name='CustomerMailboxOption',
fields=[
('customerhostingpackageoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.CustomerHostingPackageOption')),
('number', models.PositiveIntegerField(unique=True, verbose_name='number of mailboxes')),
],
options={
'ordering': ['number'],
'abstract': False,
'verbose_name': 'Mailbox option',
'verbose_name_plural': 'Mailbox options',
},
bases=('hostingpackages.customerhostingpackageoption', models.Model),
),
migrations.CreateModel(
name='CustomerUserDatabaseOption',
fields=[
('customerhostingpackageoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.CustomerHostingPackageOption')),
('number', models.PositiveIntegerField(default=1, verbose_name='number of databases')),
('db_type', models.PositiveSmallIntegerField(verbose_name='database type', choices=[(0, 'PostgreSQL'), (1, 'MySQL')])),
],
options={
'ordering': ['db_type', 'number'],
'abstract': False,
'verbose_name': 'Database option',
'verbose_name_plural': 'Database options',
},
bases=('hostingpackages.customerhostingpackageoption', models.Model),
),
migrations.CreateModel(
name='HostingOption',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
],
options={
'verbose_name': 'Hosting option',
'verbose_name_plural': 'Hosting options',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DiskSpaceOption',
fields=[
('hostingoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.HostingOption')),
('diskspace', models.PositiveIntegerField(verbose_name='disk space')),
('diskspace_unit', models.PositiveSmallIntegerField(verbose_name='unit of disk space', choices=[(0, 'MiB'), (1, 'GiB'), (2, 'TiB')])),
],
options={
'ordering': ['diskspace_unit', 'diskspace'],
'abstract': False,
'verbose_name': 'Disk space option',
'verbose_name_plural': 'Disk space options',
},
bases=('hostingpackages.hostingoption', models.Model),
),
migrations.CreateModel(
name='HostingPackageTemplate',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('name', models.CharField(unique=True, max_length=128, verbose_name='name')),
('description', models.TextField(verbose_name='description', blank=True)),
('mailboxcount', models.PositiveIntegerField(verbose_name='mailbox count')),
('diskspace', models.PositiveIntegerField(help_text='disk space for the hosting package', verbose_name='disk space')),
('diskspace_unit', models.PositiveSmallIntegerField(verbose_name='unit of disk space', choices=[(0, 'MiB'), (1, 'GiB'), (2, 'TiB')])),
],
options={
'verbose_name': 'Hosting package',
'verbose_name_plural': 'Hosting packages',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='MailboxOption',
fields=[
('hostingoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.HostingOption')),
('number', models.PositiveIntegerField(unique=True, verbose_name='number of mailboxes')),
],
options={
'ordering': ['number'],
'abstract': False,
'verbose_name': 'Mailbox option',
'verbose_name_plural': 'Mailbox options',
},
bases=('hostingpackages.hostingoption', models.Model),
),
migrations.CreateModel(
name='UserDatabaseOption',
fields=[
('hostingoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.HostingOption')),
('number', models.PositiveIntegerField(default=1, verbose_name='number of databases')),
('db_type', models.PositiveSmallIntegerField(verbose_name='database type', choices=[(0, 'PostgreSQL'), (1, 'MySQL')])),
],
options={
'ordering': ['db_type', 'number'],
'abstract': False,
'verbose_name': 'Database option',
'verbose_name_plural': 'Database options',
},
bases=('hostingpackages.hostingoption', models.Model),
),
migrations.AlterUniqueTogether(
name='userdatabaseoption',
unique_together=set([('number', 'db_type')]),
),
migrations.AlterUniqueTogether(
name='diskspaceoption',
unique_together=set([('diskspace', 'diskspace_unit')]),
),
migrations.AddField(
model_name='customeruserdatabaseoption',
name='template',
field=models.ForeignKey(verbose_name='user database option template', to='hostingpackages.UserDatabaseOption', help_text='The user database option template that this hosting option is based on'),
preserve_default=True,
),
migrations.AlterUniqueTogether(
name='customeruserdatabaseoption',
unique_together=set([('number', 'db_type')]),
),
migrations.AddField(
model_name='customermailboxoption',
name='template',
field=models.ForeignKey(verbose_name='mailbox option template', to='hostingpackages.UserDatabaseOption', help_text='The mailbox option template that this hosting option is based on'),
preserve_default=True,
),
migrations.AddField(
model_name='customerhostingpackageoption',
name='hosting_package',
field=models.ForeignKey(verbose_name='hosting package', to='hostingpackages.CustomerHostingPackage'),
preserve_default=True,
),
migrations.AddField(
model_name='customerhostingpackage',
name='template',
field=models.ForeignKey(verbose_name='hosting package template', to='hostingpackages.HostingPackageTemplate', help_text='The hosting package template that this hosting package is based on.'),
preserve_default=True,
),
migrations.AddField(
model_name='customerdiskspaceoption',
name='template',
field=models.ForeignKey(verbose_name='disk space option template', to='hostingpackages.DiskSpaceOption', help_text='The disk space option template that this hosting option is based on'),
preserve_default=True,
),
migrations.AlterUniqueTogether(
name='customerdiskspaceoption',
unique_together=set([('diskspace', 'diskspace_unit')]),
),
]

View file

@ -0,0 +1,245 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.utils.timezone
from django.conf import settings
import model_utils.fields
class Migration(migrations.Migration):
replaces = [('hostingpackages', '0001_initial'), ('hostingpackages', '0002_auto_20150118_1149'), ('hostingpackages', '0003_auto_20150118_1221'), ('hostingpackages', '0004_customerhostingpackage_osuser'), ('hostingpackages', '0005_auto_20150118_1303')]
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('osusers', '0004_auto_20150104_1751'),
]
operations = [
migrations.CreateModel(
name='CustomerHostingPackage',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('name', models.CharField(unique=True, max_length=128, verbose_name='name')),
('description', models.TextField(verbose_name='description', blank=True)),
('mailboxcount', models.PositiveIntegerField(verbose_name='mailbox count')),
('diskspace', models.PositiveIntegerField(help_text='disk space for the hosting package', verbose_name='disk space')),
('diskspace_unit', models.PositiveSmallIntegerField(verbose_name='unit of disk space', choices=[(0, 'MiB'), (1, 'GiB'), (2, 'TiB')])),
('customer', models.ForeignKey(verbose_name='customer', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'customer hosting package',
'verbose_name_plural': 'customer hosting packages',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='CustomerHostingPackageOption',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
],
options={
'verbose_name': 'customer hosting option',
'verbose_name_plural': 'customer hosting options',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='CustomerDiskSpaceOption',
fields=[
('customerhostingpackageoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.CustomerHostingPackageOption')),
('diskspace', models.PositiveIntegerField(verbose_name='disk space')),
('diskspace_unit', models.PositiveSmallIntegerField(verbose_name='unit of disk space', choices=[(0, 'MiB'), (1, 'GiB'), (2, 'TiB')])),
],
options={
'ordering': ['diskspace_unit', 'diskspace'],
'abstract': False,
'verbose_name': 'Disk space option',
'verbose_name_plural': 'Disk space options',
},
bases=('hostingpackages.customerhostingpackageoption', models.Model),
),
migrations.CreateModel(
name='CustomerMailboxOption',
fields=[
('customerhostingpackageoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.CustomerHostingPackageOption')),
('number', models.PositiveIntegerField(unique=True, verbose_name='number of mailboxes')),
],
options={
'ordering': ['number'],
'abstract': False,
'verbose_name': 'Mailbox option',
'verbose_name_plural': 'Mailbox options',
},
bases=('hostingpackages.customerhostingpackageoption', models.Model),
),
migrations.CreateModel(
name='CustomerUserDatabaseOption',
fields=[
('customerhostingpackageoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.CustomerHostingPackageOption')),
('number', models.PositiveIntegerField(default=1, verbose_name='number of databases')),
('db_type', models.PositiveSmallIntegerField(verbose_name='database type', choices=[(0, 'PostgreSQL'), (1, 'MySQL')])),
],
options={
'ordering': ['db_type', 'number'],
'abstract': False,
'verbose_name': 'Database option',
'verbose_name_plural': 'Database options',
},
bases=('hostingpackages.customerhostingpackageoption', models.Model),
),
migrations.CreateModel(
name='HostingOption',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
],
options={
'verbose_name': 'Hosting option',
'verbose_name_plural': 'Hosting options',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DiskSpaceOption',
fields=[
('hostingoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.HostingOption')),
('diskspace', models.PositiveIntegerField(verbose_name='disk space')),
('diskspace_unit', models.PositiveSmallIntegerField(verbose_name='unit of disk space', choices=[(0, 'MiB'), (1, 'GiB'), (2, 'TiB')])),
],
options={
'ordering': ['diskspace_unit', 'diskspace'],
'abstract': False,
'verbose_name': 'Disk space option',
'verbose_name_plural': 'Disk space options',
},
bases=('hostingpackages.hostingoption', models.Model),
),
migrations.CreateModel(
name='HostingPackageTemplate',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('name', models.CharField(unique=True, max_length=128, verbose_name='name')),
('description', models.TextField(verbose_name='description', blank=True)),
('mailboxcount', models.PositiveIntegerField(verbose_name='mailbox count')),
('diskspace', models.PositiveIntegerField(help_text='disk space for the hosting package', verbose_name='disk space')),
('diskspace_unit', models.PositiveSmallIntegerField(verbose_name='unit of disk space', choices=[(0, 'MiB'), (1, 'GiB'), (2, 'TiB')])),
],
options={
'verbose_name': 'Hosting package',
'verbose_name_plural': 'Hosting packages',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='MailboxOption',
fields=[
('hostingoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.HostingOption')),
('number', models.PositiveIntegerField(unique=True, verbose_name='number of mailboxes')),
],
options={
'ordering': ['number'],
'abstract': False,
'verbose_name': 'Mailbox option',
'verbose_name_plural': 'Mailbox options',
},
bases=('hostingpackages.hostingoption', models.Model),
),
migrations.CreateModel(
name='UserDatabaseOption',
fields=[
('hostingoption_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='hostingpackages.HostingOption')),
('number', models.PositiveIntegerField(default=1, verbose_name='number of databases')),
('db_type', models.PositiveSmallIntegerField(verbose_name='database type', choices=[(0, 'PostgreSQL'), (1, 'MySQL')])),
],
options={
'ordering': ['db_type', 'number'],
'abstract': False,
'verbose_name': 'Database option',
'verbose_name_plural': 'Database options',
},
bases=('hostingpackages.hostingoption', models.Model),
),
migrations.AlterUniqueTogether(
name='userdatabaseoption',
unique_together=set([('number', 'db_type')]),
),
migrations.AlterUniqueTogether(
name='diskspaceoption',
unique_together=set([('diskspace', 'diskspace_unit')]),
),
migrations.AddField(
model_name='customeruserdatabaseoption',
name='template',
field=models.ForeignKey(verbose_name='user database option template', to='hostingpackages.UserDatabaseOption', help_text='The user database option template that this hosting option is based on'),
preserve_default=True,
),
migrations.AlterUniqueTogether(
name='customeruserdatabaseoption',
unique_together=set([('number', 'db_type')]),
),
migrations.AddField(
model_name='customermailboxoption',
name='template',
field=models.ForeignKey(verbose_name='mailbox option template', to='hostingpackages.UserDatabaseOption', help_text='The mailbox option template that this mailbox option is based on'),
preserve_default=True,
),
migrations.AddField(
model_name='customerhostingpackageoption',
name='hosting_package',
field=models.ForeignKey(verbose_name='hosting package', to='hostingpackages.CustomerHostingPackage'),
preserve_default=True,
),
migrations.AddField(
model_name='customerhostingpackage',
name='template',
field=models.ForeignKey(verbose_name='hosting package template', to='hostingpackages.HostingPackageTemplate', help_text='The hosting package template that this hosting package is based on'),
preserve_default=True,
),
migrations.AddField(
model_name='customerdiskspaceoption',
name='template',
field=models.ForeignKey(verbose_name='disk space option template', to='hostingpackages.DiskSpaceOption', help_text='The disk space option template that this hosting option is based on'),
preserve_default=True,
),
migrations.AlterUniqueTogether(
name='customerdiskspaceoption',
unique_together=set([('diskspace', 'diskspace_unit')]),
),
migrations.AlterField(
model_name='customerdiskspaceoption',
name='template',
field=models.ForeignKey(verbose_name='disk space option template', to='hostingpackages.DiskSpaceOption', help_text='The disk space option template that this disk space option is based on'),
preserve_default=True,
),
migrations.AlterField(
model_name='customeruserdatabaseoption',
name='template',
field=models.ForeignKey(verbose_name='user database option template', to='hostingpackages.UserDatabaseOption', help_text='The user database option template that this database option is based on'),
preserve_default=True,
),
migrations.AlterField(
model_name='customerhostingpackage',
name='name',
field=models.CharField(max_length=128, verbose_name='name'),
preserve_default=True,
),
migrations.AlterUniqueTogether(
name='customerhostingpackage',
unique_together=set([('customer', 'name')]),
),
migrations.AddField(
model_name='customerhostingpackage',
name='osuser',
field=models.OneToOneField(null=True, blank=True, to='osusers.User', verbose_name='Operating system user'),
preserve_default=True,
),
]

View file

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('hostingpackages', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='customerdiskspaceoption',
name='template',
field=models.ForeignKey(verbose_name='disk space option template', to='hostingpackages.DiskSpaceOption', help_text='The disk space option template that this disk space option is based on'),
preserve_default=True,
),
migrations.AlterField(
model_name='customerhostingpackage',
name='template',
field=models.ForeignKey(verbose_name='hosting package template', to='hostingpackages.HostingPackageTemplate', help_text='The hosting package template that this hosting package is based on'),
preserve_default=True,
),
migrations.AlterField(
model_name='customermailboxoption',
name='template',
field=models.ForeignKey(verbose_name='mailbox option template', to='hostingpackages.UserDatabaseOption', help_text='The mailbox option template that this mailbox option is based on'),
preserve_default=True,
),
migrations.AlterField(
model_name='customeruserdatabaseoption',
name='template',
field=models.ForeignKey(verbose_name='user database option template', to='hostingpackages.UserDatabaseOption', help_text='The user database option template that this database option is based on'),
preserve_default=True,
),
]

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('hostingpackages', '0001_squashed_0005_auto_20150118_1303'),
]
operations = [
migrations.AlterModelOptions(
name='hostingoption',
options={},
),
]

View file

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('hostingpackages', '0002_auto_20150118_1149'),
]
operations = [
migrations.AlterField(
model_name='customerhostingpackage',
name='name',
field=models.CharField(max_length=128, verbose_name='name'),
preserve_default=True,
),
migrations.AlterUniqueTogether(
name='customerhostingpackage',
unique_together=set([('customer', 'name')]),
),
]

View file

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('osusers', '0004_auto_20150104_1751'),
('hostingpackages', '0003_auto_20150118_1221'),
]
operations = [
migrations.AddField(
model_name='customerhostingpackage',
name='osuser',
field=models.ForeignKey(verbose_name='Operating system user', blank=True, to='osusers.User', null=True),
preserve_default=True,
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('hostingpackages', '0004_customerhostingpackage_osuser'),
]
operations = [
migrations.AlterField(
model_name='customerhostingpackage',
name='osuser',
field=models.OneToOneField(null=True, blank=True, to='osusers.User', verbose_name='Operating system user'),
preserve_default=True,
),
]

View file

@ -0,0 +1,242 @@
"""
This module contains the hosting package models.
"""
from __future__ import absolute_import, unicode_literals
from django.conf import settings
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _, ungettext
from model_utils import Choices
from model_utils.models import TimeStampedModel
from userdbs.models import DB_TYPES
from osusers.models import User as OsUser
DISK_SPACE_UNITS = Choices(
(0, 'M', _('MiB')),
(1, 'G', _('GiB')),
(2, 'T', _('TiB')),
)
@python_2_unicode_compatible
class HostingPackageBase(TimeStampedModel):
description = models.TextField(_('description'), blank=True)
mailboxcount = models.PositiveIntegerField(_('mailbox count'))
diskspace = models.PositiveIntegerField(
_('disk space'), help_text=_('disk space for the hosting package'))
diskspace_unit = models.PositiveSmallIntegerField(
_('unit of disk space'), choices=DISK_SPACE_UNITS)
class Meta:
abstract = True
def __str__(self):
return self.name
class HostingPackageTemplate(HostingPackageBase):
name = models.CharField(_('name'), max_length=128, unique=True)
class Meta:
verbose_name = _('Hosting package')
verbose_name_plural = _('Hosting packages')
class HostingOption(TimeStampedModel):
"""
This is the base class for several types of hosting options.
"""
@python_2_unicode_compatible
class DiskSpaceOptionBase(models.Model):
diskspace = models.PositiveIntegerField(_('disk space'))
diskspace_unit = models.PositiveSmallIntegerField(
_('unit of disk space'), choices=DISK_SPACE_UNITS)
class Meta:
abstract = True
ordering = ['diskspace_unit', 'diskspace']
unique_together = ['diskspace', 'diskspace_unit']
verbose_name = _('Disk space option')
verbose_name_plural = _('Disk space options')
def __str__(self):
return _("Additional disk space {space} {unit}").format(
space=self.diskspace, unit=self.get_diskspace_unit_display())
class DiskSpaceOption(DiskSpaceOptionBase, HostingOption):
"""
This is a class for hosting options adding additional disk space to
existing hosting packages.
"""
@python_2_unicode_compatible
class UserDatabaseOptionBase(models.Model):
number = models.PositiveIntegerField(
_('number of databases'), default=1)
db_type = models.PositiveSmallIntegerField(
_('database type'), choices=DB_TYPES)
class Meta:
abstract = True
ordering = ['db_type', 'number']
unique_together = ['number', 'db_type']
verbose_name = _('Database option')
verbose_name_plural = _('Database options')
def __str__(self):
return ungettext(
'{type} database',
'{count} {type} databases',
self.number
).format(
type=self.get_db_type_display(), count=self.number
)
class UserDatabaseOption(UserDatabaseOptionBase, HostingOption):
"""
This is a class for hosting options adding user databases to existing
hosting packages.
"""
@python_2_unicode_compatible
class MailboxOptionBase(models.Model):
"""
Base class for mailbox options.
"""
number = models.PositiveIntegerField(
_('number of mailboxes'), unique=True)
class Meta:
abstract = True
ordering = ['number']
verbose_name = _('Mailbox option')
verbose_name_plural = _('Mailbox options')
def __str__(self):
return ungettext(
'{count} additional mailbox',
'{count} additional mailboxes',
self.number
).format(
count=self.number
)
class MailboxOption(MailboxOptionBase, HostingOption):
"""
This is a class for hosting options adding more mailboxes to existing
hosting packages.
"""
class CustomerHostingPackageManager(models.Manager):
def create_from_template(self, customer, template, name, **kwargs):
package = CustomerHostingPackage(
customer=customer, template=template, name=name)
for attrname in ('description', 'diskspace', 'diskspace_unit',
'mailboxcount'):
setattr(package, attrname, getattr(template, attrname))
if 'commit' in kwargs and kwargs['commit'] is True:
package.save(**kwargs)
return package
class CustomerHostingPackage(HostingPackageBase):
"""
This class defines customer specific hosting packages.
"""
customer = models.ForeignKey(
settings.AUTH_USER_MODEL, verbose_name=_('customer'))
template = models.ForeignKey(
HostingPackageTemplate, verbose_name=_('hosting package template'),
help_text=_(
'The hosting package template that this hosting package is based'
' on'
))
name = models.CharField(_('name'), max_length=128)
osuser = models.OneToOneField(
OsUser, verbose_name=_('Operating system user'),
blank=True, null=True)
objects = CustomerHostingPackageManager()
class Meta:
unique_together = ['customer', 'name']
verbose_name = _('customer hosting package')
verbose_name_plural = _('customer hosting packages')
class CustomerHostingPackageOption(TimeStampedModel):
"""
This class defines options for customer hosting packages.
"""
hosting_package = models.ForeignKey(
CustomerHostingPackage, verbose_name=_('hosting package'))
class Meta:
verbose_name = _('customer hosting option')
verbose_name_plural = _('customer hosting options')
class CustomerDiskSpaceOption(DiskSpaceOptionBase,
CustomerHostingPackageOption):
"""
This is a class for customer hosting package options adding additional disk
space to existing customer hosting package.
"""
template = models.ForeignKey(
DiskSpaceOption,
verbose_name=_('disk space option template'),
help_text=_(
'The disk space option template that this disk space option is'
' based on'
))
class CustomerUserDatabaseOption(UserDatabaseOptionBase,
CustomerHostingPackageOption):
"""
This is a class for customer hosting package options adding user databases
to existing customer hosting packages.
"""
template = models.ForeignKey(
UserDatabaseOption,
verbose_name=_('user database option template'),
help_text=_(
'The user database option template that this database option is'
' based on'
))
class CustomerMailboxOption(MailboxOptionBase,
CustomerHostingPackageOption):
"""
This is a class for customer hosting package options adding additional
mailboxes to existing customer hosting packages.
"""
template = models.ForeignKey(
UserDatabaseOption,
verbose_name=_('mailbox option template'),
help_text=_(
'The mailbox option template that this mailbox option is based on'
))