implement model changes

- add new domains.apps.AppConfig to allow translatable app description for
  domains app
- link domains to a customer
- extract common functionality from domains.models.MailDomain into abstract
  domains.models.DomainBase
- add separate domains.models.HostingDomain to allow for generic external
  domains
- add new hostingpackages.models.CustomerHostingPackageDomain to assign hosting
  domains to hosting packages
This commit is contained in:
Jan Dittberner 2015-01-24 19:10:58 +01:00
parent a3e3e2a76f
commit 0c291f0510
6 changed files with 177 additions and 2 deletions

View file

@ -0,0 +1,5 @@
"""
This app takes care of domains.
"""
default_app_config = 'domains.apps.DomainAppConfig'

View file

@ -0,0 +1,17 @@
"""
This module contains the :py:class:`django.apps.AppConfig` instance for the
:py:mod:`domains` app.
"""
from __future__ import unicode_literals
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class DomainAppConfig(AppConfig):
"""
AppConfig for the :py:mod:`domains` app.
"""
name = 'domains'
verbose_name = _('Domains')

View file

@ -0,0 +1,46 @@
# -*- 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),
('domains', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='HostingDomain',
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)),
('domain', models.CharField(unique=True, max_length=128, verbose_name='domain name')),
('customer', models.ForeignKey(verbose_name='customer', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('maildomain', models.OneToOneField(null=True, to='domains.MailDomain', blank=True, help_text='assigned mail domain for this domain', verbose_name='mail domain')),
],
options={
'verbose_name': 'Hosting domain',
'verbose_name_plural': 'Hosting domains',
},
bases=(models.Model,),
),
migrations.AddField(
model_name='maildomain',
name='customer',
field=models.ForeignKey(verbose_name='customer', blank=True, to=settings.AUTH_USER_MODEL, null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='maildomain',
name='domain',
field=models.CharField(unique=True, max_length=128, verbose_name='domain name'),
preserve_default=True,
),
]

View file

@ -1,4 +1,11 @@
"""
This module contains models related to domain names.
"""
from __future__ import absolute_import, unicode_literals
from django.db import models
from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext as _
@ -6,12 +13,54 @@ from model_utils.models import TimeStampedModel
@python_2_unicode_compatible
class MailDomain(TimeStampedModel, models.Model):
domain = models.CharField(max_length=128, unique=True)
class DomainBase(TimeStampedModel):
"""
This is the base model for domains.
"""
domain = models.CharField(_('domain name'), max_length=128, unique=True)
customer = models.ForeignKey(
settings.AUTH_USER_MODEL, verbose_name=_('customer'), blank=True,
null=True)
class Meta:
abstract = True
def __str__(self):
return self.name
@python_2_unicode_compatible
class MailDomain(DomainBase):
"""
This is the model for mail domains. Mail domains are used to configure the
mail servers (SMTP/IMAP/POP3). Mail addresses are assigned to these mail
domains.
"""
class Meta:
verbose_name = _('Mail domain')
verbose_name_plural = _('Mail domains')
def __str__(self):
return self.domain
@python_2_unicode_compatible
class HostingDomain(DomainBase):
"""
This is the model for hosting domains. A hosting domain is linked to a
customer hosting account.
"""
maildomain = models.OneToOneField(
MailDomain, verbose_name=_('mail domain'), blank=True, null=True,
help_text=_('assigned mail domain for this domain')
)
class Meta:
verbose_name = _('Hosting domain')
verbose_name_plural = _('Hosting domains')
def __str__(self):
return self.domain

View file

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.utils.timezone
import model_utils.fields
class Migration(migrations.Migration):
dependencies = [
('domains', '0002_auto_20150124_1909'),
('hostingpackages', '0003_auto_20150118_1407'),
]
operations = [
migrations.CreateModel(
name='CustomerHostingPackageDomain',
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)),
('domain', models.OneToOneField(verbose_name='hosting domain', to='domains.HostingDomain')),
('hosting_package', models.ForeignKey(related_name='domains', verbose_name='hosting package', to='hostingpackages.CustomerHostingPackage')),
],
options={
'abstract': False,
},
bases=(models.Model,),
),
]

View file

@ -14,6 +14,7 @@ from django.utils.translation import ugettext_lazy as _, ungettext
from model_utils import Choices
from model_utils.models import TimeStampedModel
from domains.models import HostingDomain
from managemails.models import Mailbox
from osusers.models import (
AdditionalGroup,
@ -66,6 +67,7 @@ class HostingOption(TimeStampedModel):
"""
@python_2_unicode_compatible
class DiskSpaceOptionBase(models.Model):
diskspace = models.PositiveIntegerField(_('disk space'))
@ -83,6 +85,7 @@ class DiskSpaceOptionBase(models.Model):
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
@ -329,6 +332,30 @@ class CustomerHostingPackage(HostingPackageBase):
return super(CustomerHostingPackage, self).save(*args, **kwargs)
@python_2_unicode_compatible
class CustomerHostingPackageDomain(TimeStampedModel):
"""
This class defines the relationship from a hosting package to a hosting
domain.
"""
hosting_package = models.ForeignKey(
CustomerHostingPackage, verbose_name=_('hosting package'),
related_name='domains')
domain = models.OneToOneField(
HostingDomain, verbose_name=_('hosting domain'))
def __str__(self):
return self.domain.domain
def is_usable_for_email(self):
"""
Tells wether the related domain is usable for email addresses.
"""
return self.domain.maildomain is not None
class CustomerHostingPackageOption(TimeStampedModel):
"""
This class defines options for customer hosting packages.