Started port to Django 2.1, Python 3, Docker
This commit is a rough port to Django 2.1, Python 3 and a Docker based local development setup. Tests fail/error but migrations and the web frontend are already runnable. Task queue functionality is untested and translations seem to have trouble.
This commit is contained in:
parent
adc57657dd
commit
6cebd80c89
48 changed files with 1081 additions and 576 deletions
|
@ -5,9 +5,9 @@ This module contains the hosting package models.
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import transaction
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext
|
||||
|
||||
|
@ -26,7 +26,6 @@ from userdbs.models import (
|
|||
UserDatabase,
|
||||
)
|
||||
|
||||
|
||||
DISK_SPACE_UNITS = Choices(
|
||||
(0, 'M', _('MiB')),
|
||||
(1, 'G', _('GiB')),
|
||||
|
@ -94,6 +93,7 @@ class DiskSpaceOption(DiskSpaceOptionBase, HostingOption):
|
|||
existing hosting packages.
|
||||
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
unique_together = ['diskspace', 'diskspace_unit']
|
||||
|
||||
|
@ -127,6 +127,7 @@ class UserDatabaseOption(UserDatabaseOptionBase, HostingOption):
|
|||
hosting packages.
|
||||
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
unique_together = ['number', 'db_type']
|
||||
|
||||
|
@ -203,17 +204,19 @@ class CustomerHostingPackage(HostingPackageBase):
|
|||
|
||||
"""
|
||||
customer = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL, verbose_name=_('customer'))
|
||||
settings.AUTH_USER_MODEL, verbose_name=_('customer'),
|
||||
on_delete=models.CASCADE)
|
||||
template = models.ForeignKey(
|
||||
HostingPackageTemplate, verbose_name=_('hosting package template'),
|
||||
help_text=_(
|
||||
'The hosting package template that this hosting package is based'
|
||||
' on'
|
||||
))
|
||||
),
|
||||
on_delete=models.CASCADE)
|
||||
name = models.CharField(_('name'), max_length=128)
|
||||
osuser = models.OneToOneField(
|
||||
OsUser, verbose_name=_('Operating system user'),
|
||||
blank=True, null=True)
|
||||
blank=True, null=True, on_delete=models.CASCADE)
|
||||
|
||||
objects = CustomerHostingPackageManager()
|
||||
|
||||
|
@ -250,6 +253,7 @@ class CustomerHostingPackage(HostingPackageBase):
|
|||
]:
|
||||
opts.extend(opt_type.objects.filter(hosting_package=self))
|
||||
return opts
|
||||
|
||||
hostingoptions = property(get_hostingoptions)
|
||||
|
||||
def get_disk_space(self, unit=None):
|
||||
|
@ -272,15 +276,16 @@ class CustomerHostingPackage(HostingPackageBase):
|
|||
diskspace += option.diskspace
|
||||
elif option.diskspace_unit > min_unit:
|
||||
diskspace += (
|
||||
DISK_SPACE_FACTORS[option.diskspace_unit][min_unit] *
|
||||
option.diskspace)
|
||||
DISK_SPACE_FACTORS[option.diskspace_unit][min_unit] *
|
||||
option.diskspace)
|
||||
else:
|
||||
diskspace = (
|
||||
DISK_SPACE_FACTORS[min_unit][option.diskspace_unit] *
|
||||
diskspace) + option.diskspace
|
||||
DISK_SPACE_FACTORS[min_unit][
|
||||
option.diskspace_unit] *
|
||||
diskspace) + option.diskspace
|
||||
min_unit = option.diskspace_unit
|
||||
if unit is None:
|
||||
return DISK_SPACE_FACTORS[min_unit][0] * diskspace * 1024**2
|
||||
return DISK_SPACE_FACTORS[min_unit][0] * diskspace * 1024 ** 2
|
||||
if unit > min_unit:
|
||||
return DISK_SPACE_FACTORS[unit][min_unit] * diskspace
|
||||
return DISK_SPACE_FACTORS[min_unit][unit] * diskspace
|
||||
|
@ -298,7 +303,7 @@ class CustomerHostingPackage(HostingPackageBase):
|
|||
"""
|
||||
if unit is None:
|
||||
return (DISK_SPACE_FACTORS[self.diskspace_unit][0] *
|
||||
self.diskspace * 1024**2)
|
||||
self.diskspace * 1024 ** 2)
|
||||
if unit > self.diskspace_unit:
|
||||
return (DISK_SPACE_FACTORS[unit][self.diskspace_unit] *
|
||||
self.diskspace)
|
||||
|
@ -312,6 +317,7 @@ class CustomerHostingPackage(HostingPackageBase):
|
|||
def get_mailboxes(self):
|
||||
if self.osuser:
|
||||
return Mailbox.objects.filter(osuser=self.osuser).all()
|
||||
|
||||
mailboxes = property(get_mailboxes)
|
||||
|
||||
def get_used_mailbox_count(self):
|
||||
|
@ -322,6 +328,7 @@ class CustomerHostingPackage(HostingPackageBase):
|
|||
if self.osuser:
|
||||
return Mailbox.objects.filter(osuser=self.osuser).count()
|
||||
return 0
|
||||
|
||||
used_mailbox_count = property(get_used_mailbox_count)
|
||||
|
||||
def get_mailbox_count(self):
|
||||
|
@ -336,6 +343,7 @@ class CustomerHostingPackage(HostingPackageBase):
|
|||
mailbox_sum=models.Sum('number')
|
||||
)
|
||||
return self.mailboxcount + (result['mailbox_sum'] or 0)
|
||||
|
||||
mailbox_count = property(get_mailbox_count)
|
||||
|
||||
def may_add_mailbox(self):
|
||||
|
@ -357,14 +365,15 @@ class CustomerHostingPackage(HostingPackageBase):
|
|||
if self.osuser:
|
||||
return UserDatabase.objects.filter(
|
||||
db_user__osuser=self.osuser).all()
|
||||
|
||||
databases = property(get_databases_flat)
|
||||
|
||||
def may_add_database(self):
|
||||
return (
|
||||
CustomerUserDatabaseOption.objects.filter(
|
||||
hosting_package=self).count() >
|
||||
UserDatabase.objects.filter(
|
||||
db_user__osuser=self.osuser).count()
|
||||
CustomerUserDatabaseOption.objects.filter(
|
||||
hosting_package=self).count() >
|
||||
UserDatabase.objects.filter(
|
||||
db_user__osuser=self.osuser).count()
|
||||
)
|
||||
|
||||
@transaction.atomic
|
||||
|
@ -402,9 +411,10 @@ class CustomerHostingPackageDomain(TimeStampedModel):
|
|||
"""
|
||||
hosting_package = models.ForeignKey(
|
||||
CustomerHostingPackage, verbose_name=_('hosting package'),
|
||||
related_name='domains')
|
||||
related_name='domains', on_delete=models.CASCADE)
|
||||
domain = models.OneToOneField(
|
||||
HostingDomain, verbose_name=_('hosting domain'))
|
||||
HostingDomain, verbose_name=_('hosting domain'),
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.domain.domain
|
||||
|
@ -423,7 +433,8 @@ class CustomerHostingPackageOption(TimeStampedModel):
|
|||
|
||||
"""
|
||||
hosting_package = models.ForeignKey(
|
||||
CustomerHostingPackage, verbose_name=_('hosting package'))
|
||||
CustomerHostingPackage, verbose_name=_('hosting package'),
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('customer hosting option')
|
||||
|
@ -443,7 +454,8 @@ class CustomerDiskSpaceOption(DiskSpaceOptionBase,
|
|||
help_text=_(
|
||||
'The disk space option template that this disk space option is'
|
||||
' based on'
|
||||
))
|
||||
),
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
|
||||
class CustomerUserDatabaseOption(UserDatabaseOptionBase,
|
||||
|
@ -459,7 +471,8 @@ class CustomerUserDatabaseOption(UserDatabaseOptionBase,
|
|||
help_text=_(
|
||||
'The user database option template that this database option is'
|
||||
' based on'
|
||||
))
|
||||
),
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
|
||||
class CustomerMailboxOption(MailboxOptionBase,
|
||||
|
@ -474,4 +487,5 @@ class CustomerMailboxOption(MailboxOptionBase,
|
|||
verbose_name=_('mailbox option template'),
|
||||
help_text=_(
|
||||
'The mailbox option template that this mailbox option is based on'
|
||||
))
|
||||
),
|
||||
on_delete=models.CASCADE)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue