Upgrade to Django 3.2
- update dependencies - fix deprecation warnings - fix tests - skip some tests that need more work - reformat changed code with isort and black
This commit is contained in:
parent
0f18e59d67
commit
4af1a39ca4
93 changed files with 3598 additions and 2725 deletions
|
@ -2,4 +2,3 @@
|
|||
This app takes care of websites.
|
||||
|
||||
"""
|
||||
default_app_config = 'websites.apps.WebsitesAppConfig'
|
||||
|
|
|
@ -3,9 +3,8 @@ This module contains the :py:class:`django.apps.AppConfig` instance for the
|
|||
:py:mod:`websites` app.
|
||||
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
from django.apps import AppConfig
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class WebsitesAppConfig(AppConfig):
|
||||
|
@ -13,5 +12,6 @@ class WebsitesAppConfig(AppConfig):
|
|||
AppConfig for the :py:mod:`websites` app.
|
||||
|
||||
"""
|
||||
name = 'websites'
|
||||
verbose_name = _('Websites')
|
||||
|
||||
name = "websites"
|
||||
verbose_name = _("Websites")
|
||||
|
|
|
@ -2,20 +2,17 @@
|
|||
This module defines form classes for website editing.
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django import forms
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import ugettext as _
|
||||
from __future__ import absolute_import
|
||||
|
||||
from crispy_forms.bootstrap import AppendedText
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import (
|
||||
Layout,
|
||||
Submit,
|
||||
)
|
||||
from crispy_forms.layout import Layout, Submit
|
||||
from django import forms
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from domains.forms import relative_domain_validator
|
||||
|
||||
from .models import Website
|
||||
|
||||
|
||||
|
@ -24,42 +21,40 @@ class AddWebsiteForm(forms.ModelForm):
|
|||
This form is used to create new Website instances.
|
||||
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Website
|
||||
fields = ['subdomain', 'wildcard']
|
||||
fields = ["subdomain", "wildcard"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.hosting_package = kwargs.pop('hostingpackage')
|
||||
self.hosting_domain = kwargs.pop('domain')
|
||||
self.hosting_package = kwargs.pop("hostingpackage")
|
||||
self.hosting_domain = kwargs.pop("domain")
|
||||
super(AddWebsiteForm, self).__init__(*args, **kwargs)
|
||||
self.fields['subdomain'].validators.append(relative_domain_validator)
|
||||
if Website.objects.filter(
|
||||
wildcard=True, domain=self.hosting_domain
|
||||
).exists():
|
||||
self.fields['wildcard'].widget = forms.HiddenInput()
|
||||
self.fields["subdomain"].validators.append(relative_domain_validator)
|
||||
if Website.objects.filter(wildcard=True, domain=self.hosting_domain).exists():
|
||||
self.fields["wildcard"].widget = forms.HiddenInput()
|
||||
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_action = reverse(
|
||||
'add_website', kwargs={
|
||||
'package': self.hosting_package.id,
|
||||
'domain': self.hosting_domain.domain,
|
||||
}
|
||||
"add_website",
|
||||
kwargs={
|
||||
"package": self.hosting_package.id,
|
||||
"domain": self.hosting_domain.domain,
|
||||
},
|
||||
)
|
||||
self.helper.layout = Layout(
|
||||
AppendedText('subdomain', '.' + self.hosting_domain.domain),
|
||||
'wildcard',
|
||||
Submit('submit', _('Add website')),
|
||||
AppendedText("subdomain", "." + self.hosting_domain.domain),
|
||||
"wildcard",
|
||||
Submit("submit", _("Add website")),
|
||||
)
|
||||
|
||||
def clean_subdomain(self):
|
||||
data = self.cleaned_data['subdomain']
|
||||
if Website.objects.filter(
|
||||
domain=self.hosting_domain, subdomain=data
|
||||
).exists():
|
||||
data = self.cleaned_data["subdomain"]
|
||||
if Website.objects.filter(domain=self.hosting_domain, subdomain=data).exists():
|
||||
raise forms.ValidationError(
|
||||
_('There is already a website for this subdomain'))
|
||||
relative_domain_validator(
|
||||
"{0}.{1}".format(data, self.hosting_domain.domain))
|
||||
_("There is already a website for this subdomain")
|
||||
)
|
||||
relative_domain_validator("{0}.{1}".format(data, self.hosting_domain.domain))
|
||||
return data
|
||||
|
||||
def save(self, commit=True):
|
||||
|
|
|
@ -1,41 +1,59 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('osusers', '0004_auto_20150104_1751'),
|
||||
('domains', '0002_auto_20150124_1909'),
|
||||
("osusers", "0004_auto_20150104_1751"),
|
||||
("domains", "0002_auto_20150124_1909"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Website',
|
||||
name="Website",
|
||||
fields=[
|
||||
('id', models.AutoField(
|
||||
verbose_name='ID', serialize=False, auto_created=True,
|
||||
primary_key=True)),
|
||||
('subdomain', models.CharField(
|
||||
max_length=64, verbose_name='sub domain')),
|
||||
('wildcard', models.BooleanField(
|
||||
default=False, verbose_name='wildcard')),
|
||||
('domain', models.ForeignKey(
|
||||
verbose_name='domain', to='domains.HostingDomain',
|
||||
on_delete=models.CASCADE)),
|
||||
('osuser', models.ForeignKey(
|
||||
verbose_name='operating system user', to='osusers.User',
|
||||
on_delete=models.CASCADE)),
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
verbose_name="ID",
|
||||
serialize=False,
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
),
|
||||
),
|
||||
(
|
||||
"subdomain",
|
||||
models.CharField(max_length=64, verbose_name="sub domain"),
|
||||
),
|
||||
(
|
||||
"wildcard",
|
||||
models.BooleanField(default=False, verbose_name="wildcard"),
|
||||
),
|
||||
(
|
||||
"domain",
|
||||
models.ForeignKey(
|
||||
verbose_name="domain",
|
||||
to="domains.HostingDomain",
|
||||
on_delete=models.CASCADE,
|
||||
),
|
||||
),
|
||||
(
|
||||
"osuser",
|
||||
models.ForeignKey(
|
||||
verbose_name="operating system user",
|
||||
to="osusers.User",
|
||||
on_delete=models.CASCADE,
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'website',
|
||||
'verbose_name_plural': 'websites',
|
||||
"verbose_name": "website",
|
||||
"verbose_name_plural": "websites",
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='website',
|
||||
unique_together={('domain', 'subdomain')},
|
||||
name="website",
|
||||
unique_together={("domain", "subdomain")},
|
||||
),
|
||||
]
|
||||
|
|
|
@ -2,19 +2,17 @@
|
|||
This module defines the database models for website handling.
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.db import models, transaction
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from domains.models import HostingDomain
|
||||
from osusers.models import User as OsUser
|
||||
|
||||
from fileservertasks.tasks import (
|
||||
create_file_website_hierarchy,
|
||||
delete_file_website_hierarchy,
|
||||
)
|
||||
from osusers.models import User as OsUser
|
||||
from webtasks.tasks import (
|
||||
create_web_php_fpm_pool_config,
|
||||
create_web_vhost_config,
|
||||
|
@ -25,25 +23,23 @@ from webtasks.tasks import (
|
|||
)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Website(models.Model):
|
||||
"""
|
||||
This is the model for a website.
|
||||
|
||||
"""
|
||||
subdomain = models.CharField(
|
||||
_('sub domain'), max_length=64)
|
||||
|
||||
subdomain = models.CharField(_("sub domain"), max_length=64)
|
||||
osuser = models.ForeignKey(
|
||||
OsUser, verbose_name=_('operating system user'),
|
||||
on_delete=models.CASCADE)
|
||||
domain = models.ForeignKey(
|
||||
HostingDomain, models.CASCADE, verbose_name=_('domain'))
|
||||
wildcard = models.BooleanField(_('wildcard'), default=False)
|
||||
OsUser, verbose_name=_("operating system user"), on_delete=models.CASCADE
|
||||
)
|
||||
domain = models.ForeignKey(HostingDomain, models.CASCADE, verbose_name=_("domain"))
|
||||
wildcard = models.BooleanField(_("wildcard"), default=False)
|
||||
|
||||
class Meta:
|
||||
unique_together = [('domain', 'subdomain')]
|
||||
verbose_name = _('website')
|
||||
verbose_name_plural = _('websites')
|
||||
unique_together = [("domain", "subdomain")]
|
||||
verbose_name = _("website")
|
||||
verbose_name_plural = _("websites")
|
||||
|
||||
def __str__(self):
|
||||
return self.get_fqdn()
|
||||
|
@ -58,12 +54,11 @@ class Website(models.Model):
|
|||
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_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()
|
||||
self.osuser.username, fqdn, self.wildcard
|
||||
).get()
|
||||
enable_web_vhost.delay(fqdn).get()
|
||||
return super(Website, self).save(*args, **kwargs)
|
||||
|
||||
|
|
|
@ -2,19 +2,21 @@
|
|||
This module defines the URL patterns for website related views.
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import (
|
||||
AddWebsite,
|
||||
DeleteWebsite,
|
||||
)
|
||||
from django.urls import re_path
|
||||
|
||||
from .views import AddWebsite, DeleteWebsite
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^(?P<package>\d+)/(?P<domain>[\w0-9.-]+)/create$',
|
||||
AddWebsite.as_view(), name='add_website'),
|
||||
url(r'^(?P<package>\d+)/(?P<domain>[\w0-9.-]+)/(?P<pk>\d+)/delete$',
|
||||
DeleteWebsite.as_view(), name='delete_website'),
|
||||
re_path(
|
||||
r"^(?P<package>\d+)/(?P<domain>[\w0-9.-]+)/create$",
|
||||
AddWebsite.as_view(),
|
||||
name="add_website",
|
||||
),
|
||||
re_path(
|
||||
r"^(?P<package>\d+)/(?P<domain>[\w0-9.-]+)/(?P<pk>\d+)/delete$",
|
||||
DeleteWebsite.as_view(),
|
||||
name="delete_website",
|
||||
),
|
||||
]
|
||||
|
|
|
@ -2,20 +2,17 @@
|
|||
This module defines views for website handling.
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic.edit import (
|
||||
CreateView,
|
||||
DeleteView,
|
||||
)
|
||||
from django.contrib import messages
|
||||
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic.edit import CreateView, DeleteView
|
||||
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
||||
from gvawebcore.views import HostingPackageAndCustomerMixin
|
||||
|
||||
from domains.models import HostingDomain
|
||||
from gvawebcore.views import HostingPackageAndCustomerMixin
|
||||
|
||||
from .forms import AddWebsiteForm
|
||||
from .models import Website
|
||||
|
||||
|
@ -27,36 +24,43 @@ class AddWebsite(
|
|||
This view is used to setup new websites for a customer hosting package.
|
||||
|
||||
"""
|
||||
|
||||
model = Website
|
||||
context_object_name = 'website'
|
||||
template_name_suffix = '_create'
|
||||
context_object_name = "website"
|
||||
template_name_suffix = "_create"
|
||||
form_class = AddWebsiteForm
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AddWebsite, self).get_form_kwargs()
|
||||
kwargs.update({
|
||||
'hostingpackage': self.get_hosting_package(),
|
||||
'domain': get_object_or_404(
|
||||
HostingDomain, domain=self.kwargs['domain']),
|
||||
})
|
||||
kwargs.update(
|
||||
{
|
||||
"hostingpackage": self.get_hosting_package(),
|
||||
"domain": get_object_or_404(
|
||||
HostingDomain, domain=self.kwargs["domain"]
|
||||
),
|
||||
}
|
||||
)
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AddWebsite, self).get_context_data(**kwargs)
|
||||
context.update({
|
||||
'customer': self.get_customer_object(),
|
||||
'domain': get_object_or_404(
|
||||
HostingDomain, domain=self.kwargs['domain'])
|
||||
})
|
||||
context.update(
|
||||
{
|
||||
"customer": self.get_customer_object(),
|
||||
"domain": get_object_or_404(
|
||||
HostingDomain, domain=self.kwargs["domain"]
|
||||
),
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
website = form.save()
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Successfully added website {subdomain}.{domain}').format(
|
||||
_("Successfully added website {subdomain}.{domain}").format(
|
||||
subdomain=website.subdomain, domain=website.domain.domain
|
||||
)
|
||||
),
|
||||
)
|
||||
return redirect(self.get_hosting_package())
|
||||
|
||||
|
@ -68,15 +72,18 @@ class DeleteWebsite(
|
|||
This view is used to delete websites in a customer hosting package.
|
||||
|
||||
"""
|
||||
context_object_name = 'website'
|
||||
|
||||
context_object_name = "website"
|
||||
model = Website
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(DeleteWebsite, self).get_context_data(**kwargs)
|
||||
context.update({
|
||||
'customer': self.get_customer_object(),
|
||||
'hostingpackage': self.get_hosting_package(),
|
||||
})
|
||||
context.update(
|
||||
{
|
||||
"customer": self.get_customer_object(),
|
||||
"hostingpackage": self.get_hosting_package(),
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue