Apply consistent Python and Django coding standards

This commit is contained in:
parkel committed 2026-11-21 02:12:32 +01:00
1 parent 1d0b5adeee
commit d7314fa927
61 files changed
+1829 -603

No files matched your search

+43 -25
View File
@@ -4,7 +4,11 @@ from django.db import models
from django.urls import reverse
from django.utils import timezone
from coulobre.database_node import DATABASE_SUFFIX_PATTERN, INVALID_SUFFIX, DatabaseSpec
from coulobre.database_node import (
DATABASE_SUFFIX_PATTERN,
INVALID_SUFFIX,
DatabaseSpec,
)
from coulobre.dns_node import (
MAX_SOA_SERIAL,
AddressRecord,
@@ -22,17 +26,20 @@ class Reseller(models.Model):
settings.AUTH_USER_MODEL,
on_delete=models.PROTECT,
related_name="hosting_reseller",
limit_choices_to={"is_superuser": False, "hosting_customer__isnull": True},
limit_choices_to={
"is_superuser": False,
"hosting_customer__isnull": True,
},
)
account_limit = models.PositiveIntegerField(default=0)
hosting_plans = models.ManyToManyField("HostingPlan", blank=True)
def may_create_accounts(self):
return self.account_limit > 0 and self.hosting_plans.exists()
def __str__(self):
return self.user.get_username()
def may_create_accounts(self):
return self.account_limit > 0 and self.hosting_plans.exists()
class Customer(models.Model):
user = models.OneToOneField(
@@ -56,12 +63,17 @@ class HostingPlan(models.Model):
database_limit = models.PositiveIntegerField(
blank=True,
null=True,
help_text="Leave blank for unlimited. Enter 0 to block new database requests.",
help_text=(
"Leave blank for unlimited. "
"Enter 0 to block new database requests."
),
)
mailbox_limit = models.PositiveIntegerField(
blank=True,
null=True,
help_text="Leave blank for unlimited. Enter 0 to block new mailbox requests.",
help_text=(
"Leave blank for unlimited. Enter 0 to block new mailbox requests."
),
)
class Meta:
@@ -85,12 +97,12 @@ class HostingAccount(models.Model):
)
created_at = models.DateTimeField(auto_now_add=True)
def get_absolute_url(self):
return reverse("panel:account", kwargs={"pk": self.pk})
def __str__(self):
return str(self.primary_domain)
def get_absolute_url(self):
return reverse("panel:account", kwargs={"pk": self.pk})
class HostingDatabase(models.Model):
account = models.ForeignKey(
@@ -112,17 +124,19 @@ class HostingDatabase(models.Model):
)
]
def __str__(self):
return self.spec.name
@property
def spec(self):
return DatabaseSpec(self.account_id, self.suffix)
def __str__(self):
return self.spec.name
class DirectAdminImport(models.Model):
account = models.OneToOneField(
HostingAccount, on_delete=models.CASCADE, related_name="directadmin_import"
HostingAccount,
on_delete=models.CASCADE,
related_name="directadmin_import",
)
fingerprint = models.CharField(max_length=64, unique=True)
@@ -148,6 +162,9 @@ class HostingDnsZone(models.Model):
)
]
def __str__(self):
return str(self.domain)
@property
def spec(self):
return DnsZone(
@@ -158,15 +175,14 @@ class HostingDnsZone(models.Model):
addresses=tuple(
AddressRecord.from_manifest(item) for item in self.addresses
),
mx_records=tuple(MxRecord.from_manifest(item) for item in self.mx_records),
mx_records=tuple(
MxRecord.from_manifest(item) for item in self.mx_records
),
txt_records=tuple(
TxtRecord.from_manifest(item) for item in self.txt_records
),
)
def __str__(self):
return str(self.domain)
class HostingMailDomain(models.Model):
account = models.ForeignKey(
@@ -193,13 +209,13 @@ class HostingMailbox(models.Model):
)
]
def __str__(self):
return self.spec.address
@property
def spec(self):
return MailboxSpec(self.mail_domain.domain, self.local_part)
def __str__(self):
return self.spec.address
class WebProvisioningPlan(models.Model):
account = models.ForeignKey(HostingAccount, on_delete=models.CASCADE)
@@ -209,6 +225,9 @@ class WebProvisioningPlan(models.Model):
completed_at = models.DateTimeField(null=True, blank=True)
apache_config = models.TextField(blank=True)
def __str__(self):
return str(self.primary_domain)
@classmethod
def for_account(cls, account):
return cls(account=account, primary_domain=account.primary_domain)
@@ -221,9 +240,6 @@ class WebProvisioningPlan(models.Model):
and self.primary_domain == self.account.primary_domain
)
def __str__(self):
return str(self.primary_domain)
class ProvisioningJobManager(models.Manager):
def queue(self, **target):
@@ -262,7 +278,9 @@ class ProvisioningJob(models.Model):
class WebActivation(ProvisioningJob):
plan = models.OneToOneField(
WebProvisioningPlan, on_delete=models.CASCADE, related_name="activation"
WebProvisioningPlan,
on_delete=models.CASCADE,
related_name="activation",
)