Merge branch 'feature/hostingpackages'

* feature/hostingpackages:
  remove newline at EOF
  add changelog entry for hosting package information on user dashboard
  render hosting package table on user dashboard
  implement get_context_data for UserDashboardView
  add CustomerHostingPackage information aggration methods
  fix foreign key for CustomerMailboxOption
  mention hostingpackages app in changelog
  add hostingpackages api doc
  add hostingpackages app to INSTALLED_APPS
  Add new hostingpackages app
This commit is contained in:
Jan Dittberner 2015-01-18 16:26:33 +01:00
commit efd5edd55f
20 changed files with 1371 additions and 6 deletions

View file

@ -1,6 +1,10 @@
Changelog Changelog
========= =========
* :feature:`-` show hosting package information on user dashboard
* :feature:`-` implement new hostingpackages app to provide hosting package
templates, hosting options and customer hosting packages as well as customer
specific hosting package options
* :feature:`-` add template tags for database icons and human readable names in * :feature:`-` add template tags for database icons and human readable names in
:py:mod:`userdbs.templatetags.userdb` :py:mod:`userdbs.templatetags.userdb`

View file

@ -16,6 +16,7 @@ administrators and customers.
code/gvacommon code/gvacommon
code/dashboard code/dashboard
code/domains code/domains
code/hostingpackages
code/managemails code/managemails
code/mysqltasks code/mysqltasks
code/osusers code/osusers

View file

@ -0,0 +1,24 @@
:py:mod:`hostingpackages` app
=============================
.. automodule:: hostingpackages
:py:mod:`admin <hostingpackages.admin>`
---------------------------------------
.. automodule:: hostingpackages.admin
:members:
:py:mod:`apps <hostingpackages.apps>`
-------------------------------------
.. automodule:: hostingpackages.apps
:members:
:py:mod:`models <hostingpackages.models>`
-----------------------------------------
.. automodule:: hostingpackages.models
:members:

View file

@ -15,6 +15,8 @@ from django.contrib.auth import get_user_model, logout
from braces.views import LoginRequiredMixin from braces.views import LoginRequiredMixin
from hostingpackages.models import CustomerHostingPackage
class IndexView(TemplateView): class IndexView(TemplateView):
""" """
@ -43,6 +45,14 @@ class UserDashboardView(LoginRequiredMixin, DetailView):
_('You are not allowed to view this page.') _('You are not allowed to view this page.')
) )
def get_context_data(self, **kwargs):
context = super(UserDashboardView, self).get_context_data(**kwargs)
context['hosting_packages'] = CustomerHostingPackage.objects.filter(
customer=self.object
)
return context
class LogoutView(RedirectView): class LogoutView(RedirectView):
pattern_name = 'dashboard' pattern_name = 'dashboard'

View file

@ -262,6 +262,7 @@ LOCAL_APPS = (
'osusers', 'osusers',
'managemails', 'managemails',
'userdbs', 'userdbs',
'hostingpackages',
) )
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps

View file

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

View file

@ -0,0 +1,145 @@
"""
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):
"""
This is the form class for creating new customer hosting packages.
"""
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):
"""
This class implements the inline editor for customer hosting package disk
space options.
"""
model = CustomerDiskSpaceOption
extra = 0
class CustomerMailboxOptionInline(admin.TabularInline):
"""
This class implements the inline editor for customer hosting package
mailbox options.
"""
model = CustomerMailboxOption
extra = 0
class CustomerUserDatabaseOptionInline(admin.TabularInline):
"""
This class implements the inline editor for customer hosting package user
database options.
"""
model = CustomerUserDatabaseOption
extra = 0
class CustomerHostingPackageAdmin(admin.ModelAdmin):
"""
This class implements the admin interface for
:py:class:`CustomerHostingPackage`.
"""
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,17 @@
"""
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:`hostingpackages` 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:36+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:192
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:185
msgid "customer"
msgstr "Kunde"
#: models.py:187
msgid "hosting package template"
msgstr "Hostingpaketvorlage"
#: models.py:189
msgid "The hosting package template that this hosting package is based on"
msgstr "Die Hostingpaketvorlage, auf der dieses Hostingpaket aufgebaut ist"
#: models.py:194
msgid "Operating system user"
msgstr "Betriebssystemnutzer"
#: models.py:201
msgid "customer hosting package"
msgstr "Kundenhostingpaket"
#: models.py:202
msgid "customer hosting packages"
msgstr "Kundenhostingpakete"
#: models.py:211
msgid "hosting package"
msgstr "Hostingpaket"
#: models.py:214
msgid "customer hosting option"
msgstr "kundenspezifische Hostingoption"
#: models.py:215
msgid "customer hosting options"
msgstr "kundenspezifische Hostingoptionen"
#: models.py:227
msgid "disk space option template"
msgstr "Speicherplatzoptionsvorlage"
#: models.py:229
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:243
msgid "user database option template"
msgstr "Nutzerdatenbankoptionsvorlage"
#: models.py:245
msgid "The user database option template that this database option is based on"
msgstr ""
"Die Nutzerdatenbankoptionsvorlage auf der diese Datenbankoption aufgebaut ist"
#: models.py:259
msgid "mailbox option template"
msgstr "Postfachoptionsvorlage"
#: models.py:261
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,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('hostingpackages', '0002_auto_20150118_1319'),
]
operations = [
migrations.AlterField(
model_name='customermailboxoption',
name='template',
field=models.ForeignKey(verbose_name='mailbox option template', to='hostingpackages.MailboxOption', help_text='The mailbox option template that this mailbox option is based on'),
preserve_default=True,
),
]

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,330 @@
"""
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 managemails.models import Mailbox
from osusers.models import User as OsUser
from userdbs.models import DB_TYPES
DISK_SPACE_UNITS = Choices(
(0, 'M', _('MiB')),
(1, 'G', _('GiB')),
(2, 'T', _('TiB')),
)
DISK_SPACE_FACTORS = (
(1, None, None),
(1024, 1, None),
(1024 * 1024, 1024, 1),
)
@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):
"""
This is the default manager implementation for
:py:class:`CustomerHostingPackage`.
"""
def create_from_template(self, customer, template, name, **kwargs):
"""
Use this method to create a new :py:class:`CustomerHostingPackage` from
a :py:class:`HostingPackageTemplate`.
The method copies data from the template to the new
:py:class:`CustomerHostingPackage` instance.
:param customer: a Django user representing a customer
:param template: a :py:class:`HostingPackageTemplate`
:param str name: the name of the hosting package there must only be
one hosting package of this name for each customer
:return: customer hosting package
:rtype: :py:class:`CustomerHostingPackage`
"""
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')
def get_disk_space(self):
"""
Get the total disk space reserved for this hosting package and all its
additional disk space options.
:return: disk space
:rtype: int
"""
diskspace = self.diskspace
min_unit = self.diskspace_unit
options = CustomerDiskSpaceOption.objects.filter(hosting_package=self)
for option in options:
if option.diskspace_unit == min_unit:
diskspace += option.disk_space
elif option.diskspace_unit > min_unit:
diskspace += (
DISK_SPACE_FACTORS[option.diskspace_unit][min_unit] *
option.diskspace)
else:
diskspace = (
DISK_SPACE_FACTORS[min_unit][option.diskspace_unit] *
diskspace) + option.diskspace
min_unit = option.diskspace_unit
return DISK_SPACE_FACTORS[min_unit][0] * diskspace * 1024**2
def get_used_mailboxes(self):
"""
Get the number of used mailboxes for this hosting package.
"""
if self.osuser:
return Mailbox.objects.filter(osuser=self.osuser).count()
return 0
def get_mailboxes(self):
"""
Get the number of mailboxes provided by this hosting package and all
of its mailbox options.
"""
result = CustomerMailboxOption.objects.filter(
hosting_package=self
).aggregate(
mailbox_sum=models.Sum('number')
)
return self.mailboxcount + result['mailbox_sum']
def get_databases(self):
"""
Get the number of user databases provided by user database hosting
options for this hosting package.
"""
return CustomerUserDatabaseOption.objects.values(
'db_type'
).filter(hosting_package=self).annotate(
number=models.Sum('number')
).all()
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(
MailboxOption,
verbose_name=_('mailbox option template'),
help_text=_(
'The mailbox option template that this mailbox option is based on'
))

View file

@ -3,10 +3,46 @@
{% block title %}{{ block.super }} - {% blocktrans with full_name=dashboard_user.get_full_name %}Dashboard for {{ full_name }}{% endblocktrans %}{% endblock title %} {% block title %}{{ block.super }} - {% blocktrans with full_name=dashboard_user.get_full_name %}Dashboard for {{ full_name }}{% endblocktrans %}{% endblock title %}
{% block page_title %}{% blocktrans with full_name=dashboard_user.get_full_name %}Dashboard for {{ full_name }}{% endblocktrans %}{% endblock page_title %} {% block page_title %}{% blocktrans with full_name=dashboard_user.get_full_name %}Dashboard for {{ full_name }}{% endblocktrans %}{% endblock page_title %}
{% block content %} {% block content %}
<p>Contract details</p> <div class="row">
<ul> <div class="col-lg-12 col-md-12 col-xs-12">
<li>Domains</li> <div class="panel panel-default">
<li>Email mailboxes</li> <div class="panel-heading">{% trans "Hosting packages" %}</div>
<li>Email addresses</li> <div class="panel-body">
</ul> {% if hosting_packages %}
<table class="table">
<thead>
<tr>
<th>{% trans "Name" %}</th>
<th>{% trans "Disk space" %}</th>
<th>{% trans "Mailboxes" %}</th>
<th>{% trans "Databases" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
</thead>
<tbody>
{% for package in hosting_packages %}
<tr>
<th>{{ package.name }}</th>
<th>
{% with diskspace=package.get_disk_space %}
<span title="{% blocktrans %}The reserved disk space for your hosting package is {{ diskspace }} bytes.{% endblocktrans %}">{{ diskspace|filesizeformat }}</span>
{% endwith %}
</th>
<th>{% blocktrans with num=package.get_used_mailboxes total=package.get_mailboxes %}used {{ num }} of {{ total }}{% endblocktrans %}</th>
<th>{% for dbtype in package.get_databases %}
{{ dbtype.number }} {% include "userdbs/snippets/db_type.html" with db_type=dbtype.db_type %}
{% if not forloop.last %} / {% endif %}
{% endfor %}</th>
<th></th>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="text-info">{% trans "You have no hosting packages yet." %}</p>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock content %} {% endblock content %}