2015-01-24 19:10:58 +01:00
|
|
|
"""
|
|
|
|
This module contains models related to domain names.
|
|
|
|
|
|
|
|
"""
|
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
|
2015-01-25 00:38:42 +01:00
|
|
|
from django.db import models, transaction
|
2015-01-24 19:10:58 +01:00
|
|
|
from django.conf import settings
|
2014-05-25 14:53:58 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
|
|
from model_utils.models import TimeStampedModel
|
|
|
|
|
|
|
|
|
|
|
|
@python_2_unicode_compatible
|
2015-01-24 19:10:58 +01:00
|
|
|
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):
|
2015-10-15 21:50:18 +02:00
|
|
|
return self.domain
|
2015-01-24 19:10:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
@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.
|
2014-05-25 14:53:58 +02:00
|
|
|
|
2015-01-24 19:10:58 +01:00
|
|
|
"""
|
2014-05-25 14:53:58 +02:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Mail domain')
|
|
|
|
verbose_name_plural = _('Mail domains')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.domain
|
2015-01-24 19:10:58 +01:00
|
|
|
|
2015-01-24 21:01:37 +01:00
|
|
|
def get_mailaddresses(self):
|
|
|
|
"""
|
|
|
|
Get a list of mail addresses assigned to this mail domain.
|
|
|
|
|
|
|
|
"""
|
|
|
|
return self.mailaddress_set.all()
|
|
|
|
mailaddresses = property(get_mailaddresses)
|
|
|
|
|
|
|
|
|
2015-01-25 00:38:42 +01:00
|
|
|
class HostingDomainManager(models.Manager):
|
|
|
|
"""
|
|
|
|
Default Manager for :py:class:`HostingDomain`.
|
|
|
|
|
|
|
|
"""
|
|
|
|
@transaction.atomic
|
|
|
|
def create_for_hosting_package(
|
|
|
|
self, hosting_package, domain, commit, **kwargs
|
|
|
|
):
|
|
|
|
from hostingpackages.models import CustomerHostingPackageDomain
|
|
|
|
hostingdomain = self.create(
|
|
|
|
customer=hosting_package.customer, domain=domain, **kwargs)
|
|
|
|
hostingdomain.maildomain = MailDomain.objects.create(
|
|
|
|
customer=hosting_package.customer, domain=domain)
|
|
|
|
custdomain = CustomerHostingPackageDomain.objects.create(
|
|
|
|
hosting_package=hosting_package, domain=hostingdomain)
|
|
|
|
if commit:
|
|
|
|
hostingdomain.save()
|
|
|
|
custdomain.save()
|
|
|
|
return hostingdomain
|
|
|
|
|
2015-01-24 19:10:58 +01:00
|
|
|
|
|
|
|
@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')
|
|
|
|
)
|
|
|
|
|
2015-01-25 00:38:42 +01:00
|
|
|
objects = HostingDomainManager()
|
|
|
|
|
2015-01-24 19:10:58 +01:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Hosting domain')
|
|
|
|
verbose_name_plural = _('Hosting domains')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.domain
|