implement website.models.Website.save

- implement save method and let it call these tasks:
  - create_web_php_fpm_pool_config if the user has no website yet
  - create_file_website_hierarchy
  - create_web_vhost_config
  - enable_web_vhost
This commit is contained in:
Jan Dittberner 2015-01-27 18:40:22 +01:00
parent 7c9509c159
commit be1e7bd27f

View file

@ -4,13 +4,22 @@ This module defines the database models for website handling.
"""
from __future__ import absolute_import, unicode_literals
from django.db import models
from django.db import models, transaction
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext as _
from domains.models import HostingDomain
from osusers.models import User as OsUser
from fileservertasks.tasks import (
create_file_website_hierarchy,
)
from webtasks.tasks import (
create_web_php_fpm_pool_config,
create_web_vhost_config,
enable_web_vhost,
)
@python_2_unicode_compatible
class Website(models.Model):
@ -32,6 +41,23 @@ class Website(models.Model):
verbose_name_plural = _('websites')
def __str__(self):
return self.get_fqdn()
def get_fqdn(self):
return "{subdomain}.{domain}".format(
subdomain=self.subdomain, domain=self.domain.domain
)
@transaction.atomic
def save(self, *args, **kwargs):
if not self.pk:
fqdn = self.get_fqdn()
if not Website.objects.filter(osuser=self.osuser).exists():
create_web_php_fpm_pool_config.delay(
self.osuser.username).get()
create_file_website_hierarchy.delay(
self.osuser.username, fqdn).get()
create_web_vhost_config.delay(
self.osuser.username, fqdn, self.wildcard).get()
enable_web_vhost.delay(fqdn).get()
return super(Website, self).save(*args, **kwargs)