templates: Add new context variables to all templates.

This adds a few new helpful context variables that we can use to
compute URLs in all of our templates:
* external_uri_scheme: http(s)://
* server_uri: The base URL for the server's canonical name
* realm_uri: The base URL for the user's realm

This is preparatory work for making realm_uri != server_uri when we
add support for subdomains.
This commit is contained in:
Tim Abbott
2016-08-13 15:57:45 -07:00
parent 4a46b879ee
commit 4fbb8c3eee
7 changed files with 38 additions and 8 deletions

View File

@@ -9,7 +9,14 @@ from zproject.backends import (password_auth_enabled, dev_auth_enabled,
def add_settings(request):
# type: (HttpRequest) -> Dict[str, Any]
realm = request.user.realm if hasattr(request.user, "realm") else None
if hasattr(request.user, "realm"):
realm = request.user.realm
realm_uri = realm.uri
else:
realm = None
# TODO: Figure out how to add an assertion that this is not used
realm_uri = settings.SERVER_URI
return {
'custom_logo_url': settings.CUSTOM_LOGO_URL,
'register_link_disabled': settings.REGISTER_LINK_DISABLED,
@@ -20,7 +27,10 @@ def add_settings(request):
'only_sso': settings.ONLY_SSO,
'external_api_path': settings.EXTERNAL_API_PATH,
'external_api_uri': settings.EXTERNAL_API_URI,
'external_host': settings.EXTERNAL_HOST,
'external_uri_scheme': settings.EXTERNAL_URI_SCHEME,
'realm_uri': realm_uri,
'server_uri': settings.SERVER_URI,
'api_site_required': settings.EXTERNAL_API_PATH != "api.zulip.com",
'email_integration_enabled': settings.EMAIL_GATEWAY_BOT != "",
'email_gateway_example': settings.EMAIL_GATEWAY_EXAMPLE,