Replace Context by dict
Since Django 1.10 template objects returned by get_template() and select_template() no longer accept a Context in their render() method.
This commit is contained in:
parent
06c226d302
commit
9953124a95
|
@ -5,7 +5,7 @@ from django import forms
|
||||||
from django.contrib.admin import helpers
|
from django.contrib.admin import helpers
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django.forms.models import modelformset_factory, BaseModelFormSet
|
from django.forms.models import modelformset_factory, BaseModelFormSet
|
||||||
from django.template import Template, Context
|
from django.template import Template
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from orchestra.forms.widgets import SpanWidget
|
from orchestra.forms.widgets import SpanWidget
|
||||||
|
@ -28,9 +28,9 @@ class AdminFormMixin(object):
|
||||||
' {% include "admin/includes/fieldset.html" %}'
|
' {% include "admin/includes/fieldset.html" %}'
|
||||||
'{% endfor %}'
|
'{% endfor %}'
|
||||||
)
|
)
|
||||||
context = Context({
|
context = {
|
||||||
'adminform': adminform
|
'adminform': adminform
|
||||||
})
|
}
|
||||||
return template.render(context)
|
return template.render(context)
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,9 +71,9 @@ class AdminFormSet(BaseModelFormSet):
|
||||||
</div>
|
</div>
|
||||||
</div>""")
|
</div>""")
|
||||||
)
|
)
|
||||||
context = Context({
|
context = {
|
||||||
'formset': self
|
'formset': self
|
||||||
})
|
}
|
||||||
return template.render(context)
|
return template.render(context)
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class AdminPasswordChangeForm(forms.Form):
|
||||||
required=False, validators=[validate_password])
|
required=False, validators=[validate_password])
|
||||||
password2 = forms.CharField(label=_("Password (again)"), widget=forms.PasswordInput,
|
password2 = forms.CharField(label=_("Password (again)"), widget=forms.PasswordInput,
|
||||||
required=False)
|
required=False)
|
||||||
|
|
||||||
def __init__(self, user, *args, **kwargs):
|
def __init__(self, user, *args, **kwargs):
|
||||||
self.related = kwargs.pop('related', [])
|
self.related = kwargs.pop('related', [])
|
||||||
self.raw = kwargs.pop('raw', False)
|
self.raw = kwargs.pop('raw', False)
|
||||||
|
@ -109,7 +109,7 @@ class AdminPasswordChangeForm(forms.Form):
|
||||||
self.fields['password2_%i' % ix] = forms.CharField(label=_("Password (again)"),
|
self.fields['password2_%i' % ix] = forms.CharField(label=_("Password (again)"),
|
||||||
widget=forms.PasswordInput, required=False)
|
widget=forms.PasswordInput, required=False)
|
||||||
setattr(self, 'clean_password2_%i' % ix, partial(self.clean_password2, ix=ix))
|
setattr(self, 'clean_password2_%i' % ix, partial(self.clean_password2, ix=ix))
|
||||||
|
|
||||||
def clean_password2(self, ix=''):
|
def clean_password2(self, ix=''):
|
||||||
if ix != '':
|
if ix != '':
|
||||||
ix = '_%i' % ix
|
ix = '_%i' % ix
|
||||||
|
@ -129,7 +129,7 @@ class AdminPasswordChangeForm(forms.Form):
|
||||||
code='password_mismatch',
|
code='password_mismatch',
|
||||||
)
|
)
|
||||||
return password2
|
return password2
|
||||||
|
|
||||||
def clean_password(self, ix=''):
|
def clean_password(self, ix=''):
|
||||||
if ix != '':
|
if ix != '':
|
||||||
ix = '_%i' % ix
|
ix = '_%i' % ix
|
||||||
|
@ -146,14 +146,14 @@ class AdminPasswordChangeForm(forms.Form):
|
||||||
code='bad_hash',
|
code='bad_hash',
|
||||||
)
|
)
|
||||||
return password
|
return password
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if not self.password_provided:
|
if not self.password_provided:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
self.error_messages['password_missing'],
|
self.error_messages['password_missing'],
|
||||||
code='password_missing',
|
code='password_missing',
|
||||||
)
|
)
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
"""
|
"""
|
||||||
Saves the new password.
|
Saves the new password.
|
||||||
|
@ -182,7 +182,7 @@ class AdminPasswordChangeForm(forms.Form):
|
||||||
if commit:
|
if commit:
|
||||||
rel.save(update_fields=['password'])
|
rel.save(update_fields=['password'])
|
||||||
return self.user
|
return self.user
|
||||||
|
|
||||||
def _get_changed_data(self):
|
def _get_changed_data(self):
|
||||||
data = super().changed_data
|
data = super().changed_data
|
||||||
for name in self.fields.keys():
|
for name in self.fields.keys():
|
||||||
|
@ -202,7 +202,7 @@ class SendEmailForm(forms.Form):
|
||||||
widget=forms.TextInput(attrs={'size': '118'}))
|
widget=forms.TextInput(attrs={'size': '118'}))
|
||||||
message = forms.CharField(label=_("Message"),
|
message = forms.CharField(label=_("Message"),
|
||||||
widget=forms.Textarea(attrs={'cols': 118, 'rows': 15}))
|
widget=forms.Textarea(attrs={'cols': 118, 'rows': 15}))
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
initial = kwargs.get('initial')
|
initial = kwargs.get('initial')
|
||||||
|
@ -210,7 +210,7 @@ class SendEmailForm(forms.Form):
|
||||||
self.fields['to'].widget = SpanWidget(original=initial['to'])
|
self.fields['to'].widget = SpanWidget(original=initial['to'])
|
||||||
else:
|
else:
|
||||||
self.fields.pop('to')
|
self.fields.pop('to')
|
||||||
|
|
||||||
def clean_comma_separated_emails(self, value):
|
def clean_comma_separated_emails(self, value):
|
||||||
clean_value = []
|
clean_value = []
|
||||||
for email in value.split(','):
|
for email in value.split(','):
|
||||||
|
@ -222,7 +222,7 @@ class SendEmailForm(forms.Form):
|
||||||
raise validators.ValidationError("Comma separated email addresses.")
|
raise validators.ValidationError("Comma separated email addresses.")
|
||||||
clean_value.append(email)
|
clean_value.append(email)
|
||||||
return clean_value
|
return clean_value
|
||||||
|
|
||||||
def clean_extra_to(self):
|
def clean_extra_to(self):
|
||||||
extra_to = self.cleaned_data['extra_to']
|
extra_to = self.cleaned_data['extra_to']
|
||||||
return self.clean_comma_separated_emails(extra_to)
|
return self.clean_comma_separated_emails(extra_to)
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.core.validators import ValidationError, RegexValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import F, Sum
|
from django.db.models import F, Sum
|
||||||
from django.db.models.functions import Coalesce
|
from django.db.models.functions import Coalesce
|
||||||
from django.template import loader, Context
|
from django.template import loader
|
||||||
from django.utils import timezone, translation
|
from django.utils import timezone, translation
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
@ -303,7 +303,7 @@ class Bill(models.Model):
|
||||||
with translation.override(language or self.account.language):
|
with translation.override(language or self.account.language):
|
||||||
if payment is False:
|
if payment is False:
|
||||||
payment = self.account.paymentsources.get_default()
|
payment = self.account.paymentsources.get_default()
|
||||||
context = Context({
|
context = {
|
||||||
'bill': self,
|
'bill': self,
|
||||||
'lines': self.lines.all().prefetch_related('sublines'),
|
'lines': self.lines.all().prefetch_related('sublines'),
|
||||||
'seller': self.seller,
|
'seller': self.seller,
|
||||||
|
@ -318,7 +318,7 @@ class Bill(models.Model):
|
||||||
'payment': payment and payment.get_bill_context(),
|
'payment': payment and payment.get_bill_context(),
|
||||||
'default_due_date': self.get_due_date(payment=payment),
|
'default_due_date': self.get_due_date(payment=payment),
|
||||||
'now': timezone.now(),
|
'now': timezone.now(),
|
||||||
})
|
}
|
||||||
template_name = 'BILLS_%s_TEMPLATE' % self.get_type()
|
template_name = 'BILLS_%s_TEMPLATE' % self.get_type()
|
||||||
template = getattr(settings, template_name, settings.BILLS_DEFAULT_TEMPLATE)
|
template = getattr(settings, template_name, settings.BILLS_DEFAULT_TEMPLATE)
|
||||||
bill_template = loader.get_template(template)
|
bill_template = loader.get_template(template)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import os
|
||||||
import textwrap
|
import textwrap
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from django.template import Template, Context
|
from django.template import Template
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from orchestra.contrib.orchestration import ServiceController
|
from orchestra.contrib.orchestration import ServiceController
|
||||||
|
@ -17,7 +17,7 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
It handles switching between these two PHP process management systemes.
|
It handles switching between these two PHP process management systemes.
|
||||||
"""
|
"""
|
||||||
MERGE = settings.WEBAPPS_MERGE_PHP_WEBAPPS
|
MERGE = settings.WEBAPPS_MERGE_PHP_WEBAPPS
|
||||||
|
|
||||||
verbose_name = _("PHP FPM/FCGID")
|
verbose_name = _("PHP FPM/FCGID")
|
||||||
default_route_match = "webapp.type.endswith('php')"
|
default_route_match = "webapp.type.endswith('php')"
|
||||||
doc_settings = (settings, (
|
doc_settings = (settings, (
|
||||||
|
@ -30,7 +30,7 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
'WEBAPPS_PHPFPM_POOL_PATH',
|
'WEBAPPS_PHPFPM_POOL_PATH',
|
||||||
'WEBAPPS_PHP_MAX_REQUESTS',
|
'WEBAPPS_PHP_MAX_REQUESTS',
|
||||||
))
|
))
|
||||||
|
|
||||||
def save(self, webapp):
|
def save(self, webapp):
|
||||||
self.delete_old_config(webapp)
|
self.delete_old_config(webapp)
|
||||||
context = self.get_context(webapp)
|
context = self.get_context(webapp)
|
||||||
|
@ -81,7 +81,7 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
}
|
}
|
||||||
""") % context
|
""") % context
|
||||||
)
|
)
|
||||||
|
|
||||||
def save_fcgid(self, webapp, context):
|
def save_fcgid(self, webapp, context):
|
||||||
self.append("mkdir -p %(wrapper_dir)s" % context)
|
self.append("mkdir -p %(wrapper_dir)s" % context)
|
||||||
self.append(textwrap.dedent("""
|
self.append(textwrap.dedent("""
|
||||||
|
@ -118,7 +118,7 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.append("rm -f %(cmd_options_path)s\n" % context)
|
self.append("rm -f %(cmd_options_path)s\n" % context)
|
||||||
|
|
||||||
def delete(self, webapp):
|
def delete(self, webapp):
|
||||||
context = self.get_context(webapp)
|
context = self.get_context(webapp)
|
||||||
self.delete_old_config(webapp)
|
self.delete_old_config(webapp)
|
||||||
|
@ -127,13 +127,13 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
# elif webapp.type_instance.is_fcgid:
|
# elif webapp.type_instance.is_fcgid:
|
||||||
# self.delete_fcgid(webapp, context)
|
# self.delete_fcgid(webapp, context)
|
||||||
self.delete_webapp_dir(context)
|
self.delete_webapp_dir(context)
|
||||||
|
|
||||||
def has_sibilings(self, webapp, context):
|
def has_sibilings(self, webapp, context):
|
||||||
return type(webapp).objects.filter(
|
return type(webapp).objects.filter(
|
||||||
account=webapp.account_id,
|
account=webapp.account_id,
|
||||||
data__contains='"php_version":"%s"' % context['php_version'],
|
data__contains='"php_version":"%s"' % context['php_version'],
|
||||||
).exclude(id=webapp.pk).exists()
|
).exclude(id=webapp.pk).exists()
|
||||||
|
|
||||||
def all_versions_to_delete(self, webapp, context, preserve=False):
|
def all_versions_to_delete(self, webapp, context, preserve=False):
|
||||||
context_copy = dict(context)
|
context_copy = dict(context)
|
||||||
for php_version, verbose in settings.WEBAPPS_PHP_VERSIONS:
|
for php_version, verbose in settings.WEBAPPS_PHP_VERSIONS:
|
||||||
|
@ -144,13 +144,13 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
context_copy['php_version_number'] = php_version_number
|
context_copy['php_version_number'] = php_version_number
|
||||||
if not self.MERGE or not self.has_sibilings(webapp, context_copy):
|
if not self.MERGE or not self.has_sibilings(webapp, context_copy):
|
||||||
yield context_copy
|
yield context_copy
|
||||||
|
|
||||||
def delete_fpm(self, webapp, context, preserve=False):
|
def delete_fpm(self, webapp, context, preserve=False):
|
||||||
""" delete all pools in order to efectively support changing php-fpm version """
|
""" delete all pools in order to efectively support changing php-fpm version """
|
||||||
for context_copy in self.all_versions_to_delete(webapp, context, preserve):
|
for context_copy in self.all_versions_to_delete(webapp, context, preserve):
|
||||||
context_copy['fpm_path'] = settings.WEBAPPS_PHPFPM_POOL_PATH % context_copy
|
context_copy['fpm_path'] = settings.WEBAPPS_PHPFPM_POOL_PATH % context_copy
|
||||||
self.append("rm -f %(fpm_path)s" % context_copy)
|
self.append("rm -f %(fpm_path)s" % context_copy)
|
||||||
|
|
||||||
def delete_fcgid(self, webapp, context, preserve=False):
|
def delete_fcgid(self, webapp, context, preserve=False):
|
||||||
""" delete all pools in order to efectively support changing php-fcgid version """
|
""" delete all pools in order to efectively support changing php-fcgid version """
|
||||||
for context_copy in self.all_versions_to_delete(webapp, context, preserve):
|
for context_copy in self.all_versions_to_delete(webapp, context, preserve):
|
||||||
|
@ -160,13 +160,13 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
})
|
})
|
||||||
self.append("rm -f %(wrapper_path)s" % context_copy)
|
self.append("rm -f %(wrapper_path)s" % context_copy)
|
||||||
self.append("rm -f %(cmd_options_path)s" % context_copy)
|
self.append("rm -f %(cmd_options_path)s" % context_copy)
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
super(PHPController, self).prepare()
|
super(PHPController, self).prepare()
|
||||||
self.append(textwrap.dedent("""
|
self.append(textwrap.dedent("""
|
||||||
BACKEND="PHPController"
|
BACKEND="PHPController"
|
||||||
echo "$BACKEND" >> /dev/shm/reload.apache2
|
echo "$BACKEND" >> /dev/shm/reload.apache2
|
||||||
|
|
||||||
function coordinate_apache_reload () {
|
function coordinate_apache_reload () {
|
||||||
# Coordinate Apache reload with other concurrent backends (e.g. Apache2Controller)
|
# Coordinate Apache reload with other concurrent backends (e.g. Apache2Controller)
|
||||||
is_last=0
|
is_last=0
|
||||||
|
@ -203,7 +203,7 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
fi
|
fi
|
||||||
}""")
|
}""")
|
||||||
)
|
)
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
context = {
|
context = {
|
||||||
'reload_pool': settings.WEBAPPS_PHPFPM_RELOAD_POOL,
|
'reload_pool': settings.WEBAPPS_PHPFPM_RELOAD_POOL,
|
||||||
|
@ -217,7 +217,7 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
""") % context
|
""") % context
|
||||||
)
|
)
|
||||||
super(PHPController, self).commit()
|
super(PHPController, self).commit()
|
||||||
|
|
||||||
def get_fpm_config(self, webapp, context):
|
def get_fpm_config(self, webapp, context):
|
||||||
options = webapp.type_instance.get_options()
|
options = webapp.type_instance.get_options()
|
||||||
context.update({
|
context.update({
|
||||||
|
@ -231,11 +231,11 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
[{{ user }}-{{app_name}}]
|
[{{ user }}-{{app_name}}]
|
||||||
user = {{ user }}
|
user = {{ user }}
|
||||||
group = {{ group }}
|
group = {{ group }}
|
||||||
|
|
||||||
listen = {{ fpm_listen | safe }}
|
listen = {{ fpm_listen | safe }}
|
||||||
listen.owner = {{ user }}
|
listen.owner = {{ user }}
|
||||||
listen.group = {{ group }}
|
listen.group = {{ group }}
|
||||||
|
|
||||||
pm = ondemand
|
pm = ondemand
|
||||||
pm.max_requests = {{ max_requests }}
|
pm.max_requests = {{ max_requests }}
|
||||||
pm.max_children = {{ max_children }}
|
pm.max_children = {{ max_children }}
|
||||||
|
@ -245,8 +245,8 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
php_admin_value[{{ name | safe }}] = {{ value | safe }}{% endfor %}
|
php_admin_value[{{ name | safe }}] = {{ value | safe }}{% endfor %}
|
||||||
"""
|
"""
|
||||||
))
|
))
|
||||||
return fpm_config.render(Context(context))
|
return fpm_config.render(context)
|
||||||
|
|
||||||
def get_fcgid_wrapper(self, webapp, context):
|
def get_fcgid_wrapper(self, webapp, context):
|
||||||
opt = webapp.type_instance
|
opt = webapp.type_instance
|
||||||
# Format PHP init vars
|
# Format PHP init vars
|
||||||
|
@ -268,7 +268,7 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
export PHP_INI_SCAN_DIR=%(php_ini_scan)s
|
export PHP_INI_SCAN_DIR=%(php_ini_scan)s
|
||||||
export PHP_FCGI_MAX_REQUESTS=%(max_requests)s
|
export PHP_FCGI_MAX_REQUESTS=%(max_requests)s
|
||||||
exec %(php_binary_path)s%(php_init_vars)s""") % context
|
exec %(php_binary_path)s%(php_init_vars)s""") % context
|
||||||
|
|
||||||
def get_fcgid_cmd_options(self, webapp, context):
|
def get_fcgid_cmd_options(self, webapp, context):
|
||||||
options = webapp.type_instance.get_options()
|
options = webapp.type_instance.get_options()
|
||||||
maps = OrderedDict(
|
maps = OrderedDict(
|
||||||
|
@ -288,7 +288,7 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
) % context
|
) % context
|
||||||
cmd_options.insert(0, head)
|
cmd_options.insert(0, head)
|
||||||
return ' \\\n '.join(cmd_options)
|
return ' \\\n '.join(cmd_options)
|
||||||
|
|
||||||
def update_fcgid_context(self, webapp, context):
|
def update_fcgid_context(self, webapp, context):
|
||||||
wrapper_path = settings.WEBAPPS_FCGID_WRAPPER_PATH % context
|
wrapper_path = settings.WEBAPPS_FCGID_WRAPPER_PATH % context
|
||||||
context.update({
|
context.update({
|
||||||
|
@ -301,14 +301,14 @@ class PHPController(WebAppServiceMixin, ServiceController):
|
||||||
'cmd_options_path': settings.WEBAPPS_FCGID_CMD_OPTIONS_PATH % context,
|
'cmd_options_path': settings.WEBAPPS_FCGID_CMD_OPTIONS_PATH % context,
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def update_fpm_context(self, webapp, context):
|
def update_fpm_context(self, webapp, context):
|
||||||
context.update({
|
context.update({
|
||||||
'fpm_config': self.get_fpm_config(webapp, context),
|
'fpm_config': self.get_fpm_config(webapp, context),
|
||||||
'fpm_path': settings.WEBAPPS_PHPFPM_POOL_PATH % context,
|
'fpm_path': settings.WEBAPPS_PHPFPM_POOL_PATH % context,
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_context(self, webapp):
|
def get_context(self, webapp):
|
||||||
context = super().get_context(webapp)
|
context = super().get_context(webapp)
|
||||||
context.update({
|
context.update({
|
||||||
|
|
|
@ -2,7 +2,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
from django.template import Template, Context
|
from django.template import Template
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from orchestra.contrib.orchestration import ServiceController
|
from orchestra.contrib.orchestration import ServiceController
|
||||||
|
@ -20,7 +20,7 @@ class Apache2Controller(ServiceController):
|
||||||
"""
|
"""
|
||||||
HTTP_PORT = 80
|
HTTP_PORT = 80
|
||||||
HTTPS_PORT = 443
|
HTTPS_PORT = 443
|
||||||
|
|
||||||
model = 'websites.Website'
|
model = 'websites.Website'
|
||||||
related_models = (
|
related_models = (
|
||||||
('websites.Content', 'website'),
|
('websites.Content', 'website'),
|
||||||
|
@ -37,7 +37,7 @@ class Apache2Controller(ServiceController):
|
||||||
'WEBSITES_DEFAULT_IPS',
|
'WEBSITES_DEFAULT_IPS',
|
||||||
'WEBSITES_SAAS_DIRECTIVES',
|
'WEBSITES_SAAS_DIRECTIVES',
|
||||||
))
|
))
|
||||||
|
|
||||||
def get_extra_conf(self, site, context, ssl=False):
|
def get_extra_conf(self, site, context, ssl=False):
|
||||||
extra_conf = self.get_content_directives(site, context)
|
extra_conf = self.get_content_directives(site, context)
|
||||||
directives = site.get_directives()
|
directives = site.get_directives()
|
||||||
|
@ -53,7 +53,7 @@ class Apache2Controller(ServiceController):
|
||||||
# Order extra conf directives based on directives (longer first)
|
# Order extra conf directives based on directives (longer first)
|
||||||
extra_conf = sorted(extra_conf, key=lambda a: len(a[0]), reverse=True)
|
extra_conf = sorted(extra_conf, key=lambda a: len(a[0]), reverse=True)
|
||||||
return '\n'.join([conf for location, conf in extra_conf])
|
return '\n'.join([conf for location, conf in extra_conf])
|
||||||
|
|
||||||
def render_virtual_host(self, site, context, ssl=False):
|
def render_virtual_host(self, site, context, ssl=False):
|
||||||
context.update({
|
context.update({
|
||||||
'port': self.HTTPS_PORT if ssl else self.HTTP_PORT,
|
'port': self.HTTPS_PORT if ssl else self.HTTP_PORT,
|
||||||
|
@ -78,8 +78,8 @@ class Apache2Controller(ServiceController):
|
||||||
{{ line | safe }}{% endfor %}
|
{{ line | safe }}{% endfor %}
|
||||||
</VirtualHost>
|
</VirtualHost>
|
||||||
""")
|
""")
|
||||||
).render(Context(context))
|
).render(context)
|
||||||
|
|
||||||
def render_redirect_https(self, context):
|
def render_redirect_https(self, context):
|
||||||
context['port'] = self.HTTP_PORT
|
context['port'] = self.HTTP_PORT
|
||||||
return Template(textwrap.dedent("""
|
return Template(textwrap.dedent("""
|
||||||
|
@ -96,8 +96,8 @@ class Apache2Controller(ServiceController):
|
||||||
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
|
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
|
||||||
</VirtualHost>
|
</VirtualHost>
|
||||||
""")
|
""")
|
||||||
).render(Context(context))
|
).render(context)
|
||||||
|
|
||||||
def save(self, site):
|
def save(self, site):
|
||||||
context = self.get_context(site)
|
context = self.get_context(site)
|
||||||
if context['server_name']:
|
if context['server_name']:
|
||||||
|
@ -133,7 +133,7 @@ class Apache2Controller(ServiceController):
|
||||||
[[ $(a2dissite %(site_unique_name)s) =~ "already disabled" ]] || UPDATED_APACHE=1\
|
[[ $(a2dissite %(site_unique_name)s) =~ "already disabled" ]] || UPDATED_APACHE=1\
|
||||||
""") % context
|
""") % context
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(self, site):
|
def delete(self, site):
|
||||||
context = self.get_context(site)
|
context = self.get_context(site)
|
||||||
self.append(textwrap.dedent("""
|
self.append(textwrap.dedent("""
|
||||||
|
@ -142,14 +142,14 @@ class Apache2Controller(ServiceController):
|
||||||
rm -f %(sites_available)s\
|
rm -f %(sites_available)s\
|
||||||
""") % context
|
""") % context
|
||||||
)
|
)
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
super(Apache2Controller, self).prepare()
|
super(Apache2Controller, self).prepare()
|
||||||
# Coordinate apache restart with php backend in order not to overdo it
|
# Coordinate apache restart with php backend in order not to overdo it
|
||||||
self.append(textwrap.dedent("""
|
self.append(textwrap.dedent("""
|
||||||
BACKEND="Apache2Controller"
|
BACKEND="Apache2Controller"
|
||||||
echo "$BACKEND" >> /dev/shm/reload.apache2
|
echo "$BACKEND" >> /dev/shm/reload.apache2
|
||||||
|
|
||||||
function coordinate_apache_reload () {
|
function coordinate_apache_reload () {
|
||||||
# Coordinate Apache reload with other concurrent backends (e.g. PHPController)
|
# Coordinate Apache reload with other concurrent backends (e.g. PHPController)
|
||||||
is_last=0
|
is_last=0
|
||||||
|
@ -186,12 +186,12 @@ class Apache2Controller(ServiceController):
|
||||||
fi
|
fi
|
||||||
}""")
|
}""")
|
||||||
)
|
)
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
""" reload Apache2 if necessary """
|
""" reload Apache2 if necessary """
|
||||||
self.append("coordinate_apache_reload")
|
self.append("coordinate_apache_reload")
|
||||||
super(Apache2Controller, self).commit()
|
super(Apache2Controller, self).commit()
|
||||||
|
|
||||||
def get_directives(self, directive, context):
|
def get_directives(self, directive, context):
|
||||||
method, args = directive[0], directive[1:]
|
method, args = directive[0], directive[1:]
|
||||||
try:
|
try:
|
||||||
|
@ -200,7 +200,7 @@ class Apache2Controller(ServiceController):
|
||||||
context = (self.__class__.__name__, method)
|
context = (self.__class__.__name__, method)
|
||||||
raise AttributeError("%s does not has suport for '%s' directive." % context)
|
raise AttributeError("%s does not has suport for '%s' directive." % context)
|
||||||
return method(context, *args)
|
return method(context, *args)
|
||||||
|
|
||||||
def get_content_directives(self, site, context):
|
def get_content_directives(self, site, context):
|
||||||
directives = []
|
directives = []
|
||||||
for content in site.content_set.all():
|
for content in site.content_set.all():
|
||||||
|
@ -208,19 +208,19 @@ class Apache2Controller(ServiceController):
|
||||||
self.set_content_context(content, context)
|
self.set_content_context(content, context)
|
||||||
directives += self.get_directives(directive, context)
|
directives += self.get_directives(directive, context)
|
||||||
return directives
|
return directives
|
||||||
|
|
||||||
def get_static_directives(self, context, app_path):
|
def get_static_directives(self, context, app_path):
|
||||||
context['app_path'] = os.path.normpath(app_path % context)
|
context['app_path'] = os.path.normpath(app_path % context)
|
||||||
directive = self.get_location_filesystem_map(context)
|
directive = self.get_location_filesystem_map(context)
|
||||||
return [
|
return [
|
||||||
(context['location'], directive),
|
(context['location'], directive),
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_location_filesystem_map(self, context):
|
def get_location_filesystem_map(self, context):
|
||||||
if not context['location']:
|
if not context['location']:
|
||||||
return 'DocumentRoot %(app_path)s' % context
|
return 'DocumentRoot %(app_path)s' % context
|
||||||
return 'Alias %(location)s %(app_path)s' % context
|
return 'Alias %(location)s %(app_path)s' % context
|
||||||
|
|
||||||
def get_fpm_directives(self, context, socket, app_path):
|
def get_fpm_directives(self, context, socket, app_path):
|
||||||
if ':' in socket:
|
if ':' in socket:
|
||||||
# TCP socket
|
# TCP socket
|
||||||
|
@ -243,7 +243,7 @@ class Apache2Controller(ServiceController):
|
||||||
return [
|
return [
|
||||||
(context['location'], directives),
|
(context['location'], directives),
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_fcgid_directives(self, context, app_path, wrapper_path):
|
def get_fcgid_directives(self, context, app_path, wrapper_path):
|
||||||
context.update({
|
context.update({
|
||||||
'app_path': os.path.normpath(app_path),
|
'app_path': os.path.normpath(app_path),
|
||||||
|
@ -274,7 +274,7 @@ class Apache2Controller(ServiceController):
|
||||||
return [
|
return [
|
||||||
(context['location'], directives),
|
(context['location'], directives),
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_uwsgi_directives(self, context, socket):
|
def get_uwsgi_directives(self, context, socket):
|
||||||
# requires apache2 mod_proxy_uwsgi
|
# requires apache2 mod_proxy_uwsgi
|
||||||
context['socket'] = socket
|
context['socket'] = socket
|
||||||
|
@ -283,7 +283,7 @@ class Apache2Controller(ServiceController):
|
||||||
return [
|
return [
|
||||||
(context['location'], directives),
|
(context['location'], directives),
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_ssl(self, directives):
|
def get_ssl(self, directives):
|
||||||
cert = directives.get('ssl-cert')
|
cert = directives.get('ssl-cert')
|
||||||
key = directives.get('ssl-key')
|
key = directives.get('ssl-key')
|
||||||
|
@ -305,7 +305,7 @@ class Apache2Controller(ServiceController):
|
||||||
return [
|
return [
|
||||||
('', '\n'.join(ssl_config)),
|
('', '\n'.join(ssl_config)),
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_security(self, directives):
|
def get_security(self, directives):
|
||||||
rules = []
|
rules = []
|
||||||
location = '/'
|
location = '/'
|
||||||
|
@ -329,7 +329,7 @@ class Apache2Controller(ServiceController):
|
||||||
</IfModule>""") % '\n '.join(rules)
|
</IfModule>""") % '\n '.join(rules)
|
||||||
security.append((location, rules))
|
security.append((location, rules))
|
||||||
return security
|
return security
|
||||||
|
|
||||||
def get_redirects(self, directives):
|
def get_redirects(self, directives):
|
||||||
redirects = []
|
redirects = []
|
||||||
for redirect in directives.get('redirect', []):
|
for redirect in directives.get('redirect', []):
|
||||||
|
@ -342,7 +342,7 @@ class Apache2Controller(ServiceController):
|
||||||
(location, redirect)
|
(location, redirect)
|
||||||
)
|
)
|
||||||
return redirects
|
return redirects
|
||||||
|
|
||||||
def get_proxies(self, directives):
|
def get_proxies(self, directives):
|
||||||
proxies = []
|
proxies = []
|
||||||
for proxy in directives.get('proxy', []):
|
for proxy in directives.get('proxy', []):
|
||||||
|
@ -360,7 +360,7 @@ class Apache2Controller(ServiceController):
|
||||||
(location, proxy)
|
(location, proxy)
|
||||||
)
|
)
|
||||||
return proxies
|
return proxies
|
||||||
|
|
||||||
def get_saas(self, directives):
|
def get_saas(self, directives):
|
||||||
saas = []
|
saas = []
|
||||||
for name, values in directives.items():
|
for name, values in directives.items():
|
||||||
|
@ -372,20 +372,20 @@ class Apache2Controller(ServiceController):
|
||||||
directive = settings.WEBSITES_SAAS_DIRECTIVES[name]
|
directive = settings.WEBSITES_SAAS_DIRECTIVES[name]
|
||||||
saas += self.get_directives(directive, context)
|
saas += self.get_directives(directive, context)
|
||||||
return saas
|
return saas
|
||||||
|
|
||||||
def get_username(self, site):
|
def get_username(self, site):
|
||||||
option = site.get_directives().get('user_group')
|
option = site.get_directives().get('user_group')
|
||||||
if option:
|
if option:
|
||||||
return option[0]
|
return option[0]
|
||||||
return site.get_username()
|
return site.get_username()
|
||||||
|
|
||||||
def get_groupname(self, site):
|
def get_groupname(self, site):
|
||||||
option = site.get_directives().get('user_group')
|
option = site.get_directives().get('user_group')
|
||||||
if option and ' ' in option:
|
if option and ' ' in option:
|
||||||
user, group = option.split()
|
user, group = option.split()
|
||||||
return group
|
return group
|
||||||
return site.get_groupname()
|
return site.get_groupname()
|
||||||
|
|
||||||
def get_server_names(self, site):
|
def get_server_names(self, site):
|
||||||
server_name = None
|
server_name = None
|
||||||
server_alias = []
|
server_alias = []
|
||||||
|
@ -395,7 +395,7 @@ class Apache2Controller(ServiceController):
|
||||||
else:
|
else:
|
||||||
server_alias.append(domain.name)
|
server_alias.append(domain.name)
|
||||||
return server_name, server_alias
|
return server_name, server_alias
|
||||||
|
|
||||||
def get_context(self, site):
|
def get_context(self, site):
|
||||||
base_apache_conf = settings.WEBSITES_BASE_APACHE_CONF
|
base_apache_conf = settings.WEBSITES_BASE_APACHE_CONF
|
||||||
sites_available = os.path.join(base_apache_conf, 'sites-available')
|
sites_available = os.path.join(base_apache_conf, 'sites-available')
|
||||||
|
@ -419,7 +419,7 @@ class Apache2Controller(ServiceController):
|
||||||
if not context['ips']:
|
if not context['ips']:
|
||||||
raise ValueError("WEBSITES_DEFAULT_IPS is empty.")
|
raise ValueError("WEBSITES_DEFAULT_IPS is empty.")
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def set_content_context(self, content, context):
|
def set_content_context(self, content, context):
|
||||||
content_context = {
|
content_context = {
|
||||||
'type': content.webapp.type,
|
'type': content.webapp.type,
|
||||||
|
@ -442,7 +442,7 @@ class Apache2Traffic(ServiceMonitor):
|
||||||
doc_settings = (settings,
|
doc_settings = (settings,
|
||||||
('WEBSITES_TRAFFIC_IGNORE_HOSTS',)
|
('WEBSITES_TRAFFIC_IGNORE_HOSTS',)
|
||||||
)
|
)
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
super(Apache2Traffic, self).prepare()
|
super(Apache2Traffic, self).prepare()
|
||||||
ignore_hosts = '\\|'.join(settings.WEBSITES_TRAFFIC_IGNORE_HOSTS)
|
ignore_hosts = '\\|'.join(settings.WEBSITES_TRAFFIC_IGNORE_HOSTS)
|
||||||
|
@ -490,11 +490,11 @@ class Apache2Traffic(ServiceMonitor):
|
||||||
}' || [[ $? == 1 ]] && true
|
}' || [[ $? == 1 ]] && true
|
||||||
} | xargs echo ${OBJECT_ID}
|
} | xargs echo ${OBJECT_ID}
|
||||||
}""") % context)
|
}""") % context)
|
||||||
|
|
||||||
def monitor(self, site):
|
def monitor(self, site):
|
||||||
context = self.get_context(site)
|
context = self.get_context(site)
|
||||||
self.append('monitor {object_id} "{last_date}" {log_file}'.format(**context))
|
self.append('monitor {object_id} "{last_date}" {log_file}'.format(**context))
|
||||||
|
|
||||||
def get_context(self, site):
|
def get_context(self, site):
|
||||||
return {
|
return {
|
||||||
'log_file': '%s{,.1}' % site.get_www_access_log_path(),
|
'log_file': '%s{,.1}' % site.get_www_access_log_path(),
|
||||||
|
|
|
@ -2,7 +2,6 @@ from urllib.parse import urlparse
|
||||||
|
|
||||||
from django.core.mail import EmailMultiAlternatives
|
from django.core.mail import EmailMultiAlternatives
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.template import Context
|
|
||||||
|
|
||||||
|
|
||||||
def render_email_template(template, context):
|
def render_email_template(template, context):
|
||||||
|
|
Loading…
Reference in a new issue