-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Standardizing the use of settings directly #5632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
2f002fc
febc346
0314180
ef93560
69428bd
a150816
b92005f
56b4b4a
ce2f1d8
152355b
54e970b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,6 @@ | |
log = logging.getLogger(__name__) | ||
|
||
LOG_TEMPLATE = '(Middleware) {msg} [{host}{path}]' | ||
SUBDOMAIN_URLCONF = settings.SUBDOMAIN_URLCONF | ||
SINGLE_VERSION_URLCONF = settings.SINGLE_VERSION_URLCONF | ||
|
||
|
||
class SubdomainMiddleware(MiddlewareMixin): | ||
|
@@ -38,10 +36,9 @@ def process_request(self, request): | |
path = request.get_full_path() | ||
log_kwargs = dict(host=host, path=path) | ||
public_domain = settings.PUBLIC_DOMAIN | ||
production_domain = settings.PRODUCTION_DOMAIN | ||
|
||
if public_domain is None: | ||
public_domain = production_domain | ||
public_domain = settings.PRODUCTION_DOMAIN | ||
if ':' in host: | ||
host = host.split(':')[0] | ||
domain_parts = host.split('.') | ||
|
@@ -57,21 +54,21 @@ def process_request(self, request): | |
raise Http404(_('Project not found')) | ||
request.subdomain = True | ||
request.slug = subdomain | ||
request.urlconf = SUBDOMAIN_URLCONF | ||
request.urlconf = settings.SUBDOMAIN_URLCONF | ||
return None | ||
|
||
# Serve CNAMEs | ||
if ( | ||
public_domain not in host and production_domain not in host and | ||
'localhost' not in host and 'testserver' not in host | ||
public_domain not in host and settings.PRODUCTION_DOMAIN not in host | ||
and 'localhost' not in host and 'testserver' not in host | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't start a line with an operator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, maybe this can be written like if all(test_host not in host for test_host in ('localhost', 'testserver', public_domain, settings.PRODUCTION_DOMAIN)): (not sure if that is more readable) |
||
): | ||
request.cname = True | ||
domains = Domain.objects.filter(domain=host) | ||
if domains.count(): | ||
for domain in domains: | ||
if domain.domain == host: | ||
request.slug = domain.project.slug | ||
request.urlconf = SUBDOMAIN_URLCONF | ||
request.urlconf = settings.SUBDOMAIN_URLCONF | ||
request.domain_object = True | ||
log.debug( | ||
LOG_TEMPLATE.format( | ||
|
@@ -85,7 +82,7 @@ def process_request(self, request): | |
'HTTP_X_RTD_SLUG' in request.META | ||
): | ||
request.slug = request.META['HTTP_X_RTD_SLUG'].lower() | ||
request.urlconf = SUBDOMAIN_URLCONF | ||
request.urlconf = settings.SUBDOMAIN_URLCONF | ||
request.rtdheader = True | ||
log.debug( | ||
LOG_TEMPLATE.format( | ||
|
@@ -161,7 +158,7 @@ def process_request(self, request): | |
return None | ||
|
||
if getattr(proj, 'single_version', False): | ||
request.urlconf = SINGLE_VERSION_URLCONF | ||
request.urlconf = settings.SINGLE_VERSION_URLCONF | ||
# Logging | ||
host = request.get_host() | ||
path = request.get_full_path() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,16 +180,15 @@ def resolve( | |
else: | ||
domain = settings.PRODUCTION_DOMAIN | ||
|
||
public_domain = settings.PUBLIC_DOMAIN | ||
use_https = settings.PUBLIC_DOMAIN_USES_HTTPS | ||
|
||
use_https_protocol = any([ | ||
# Rely on the ``Domain.https`` field | ||
use_custom_domain and custom_domain.https, | ||
# or force it if specified | ||
require_https, | ||
# or fallback to settings | ||
use_https and public_domain and public_domain in domain, | ||
settings.PUBLIC_DOMAIN_USES_HTTPS | ||
and settings.PUBLIC_DOMAIN | ||
and settings.PUBLIC_DOMAIN in domain, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't start with an operator |
||
]) | ||
protocol = 'https' if use_https_protocol else 'http' | ||
|
||
|
@@ -229,11 +228,10 @@ def _get_canonical_project(self, project, projects=None): | |
|
||
def _get_project_subdomain(self, project): | ||
"""Determine canonical project domain as subdomain.""" | ||
public_domain = settings.PUBLIC_DOMAIN | ||
if self._use_subdomain(): | ||
project = self._get_canonical_project(project) | ||
subdomain_slug = project.slug.replace('_', '-') | ||
return '{}.{}'.format(subdomain_slug, public_domain) | ||
return '{}.{}'.format(subdomain_slug, settings.PUBLIC_DOMAIN) | ||
|
||
def _get_private(self, project, version_slug): | ||
from readthedocs.builds.models import Version | ||
|
@@ -266,9 +264,7 @@ def _use_custom_domain(self, custom_domain): | |
|
||
def _use_subdomain(self): | ||
"""Make decision about whether to use a subdomain to serve docs.""" | ||
use_subdomain = settings.USE_SUBDOMAIN | ||
public_domain = settings.PUBLIC_DOMAIN | ||
return use_subdomain and public_domain is not None | ||
return settings.USE_SUBDOMAIN and settings.PUBLIC_DOMAIN is not None | ||
|
||
|
||
class Resolver(SettingsOverrideObject): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,7 @@ def send_notification(request, notification): | |
should be a list of class paths to be loaded, using the standard Django | ||
string module loader. | ||
""" | ||
backends = settings.NOTIFICATION_BACKENDS | ||
for cls_name in backends: | ||
for cls_name in settings.NOTIFICATION_BACKENDS: | ||
backend = import_string(cls_name)(request) | ||
backend.send(notification) | ||
|
||
|
@@ -93,8 +92,8 @@ def send(self, notification): | |
# manipulates the storage directly. This is because we don't have a | ||
# request object and need to mock one out to fool the message storage | ||
# into saving a message for a separate user. | ||
cls_name = settings.MESSAGE_STORAGE | ||
cls = import_string(cls_name) | ||
|
||
cls = import_string(settings.MESSAGE_STORAGE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are losing readability here |
||
req = HttpRequest() | ||
setattr(req, 'session', '') | ||
storage = cls(req) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,12 +59,11 @@ class RepositoryURLValidator: | |
re_git_user = re.compile(r'^[\w]+@.+') | ||
|
||
def __call__(self, value): | ||
allow_private_repos = settings.ALLOW_PRIVATE_REPOS | ||
public_schemes = ['https', 'http', 'git', 'ftps', 'ftp'] | ||
private_schemes = ['ssh', 'ssh+git'] | ||
local_schemes = ['file'] | ||
valid_schemes = public_schemes | ||
if allow_private_repos: | ||
if settings.ALLOW_PRIVATE_REPOS: | ||
valid_schemes += private_schemes | ||
if settings.DEBUG: # allow `file://` urls in dev | ||
valid_schemes += local_schemes | ||
|
@@ -86,7 +85,7 @@ def __call__(self, value): | |
return value | ||
# SSH cloning and ``[email protected]:user/project.git`` | ||
elif self.re_git_user.search(value) or url.scheme in private_schemes: | ||
if allow_private_repos: | ||
if settings.ALLOW_PRIVATE_REPOS: | ||
return value | ||
|
||
# Throw a more helpful error message | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one can stay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different configuration files can have a different default image
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay