From 400232a10f51a72528ac8d44b2ec428ab1e9a4b4 Mon Sep 17 00:00:00 2001 From: Neil Martinsen-Burrell Date: Wed, 17 May 2023 13:59:34 -0500 Subject: [PATCH] Add public_site_url template tag --- ops/manifests/manifest-stable.yaml | 2 ++ ops/scripts/manifest-sandbox-template.yaml | 2 ++ src/.env-example | 1 + src/docker-compose.yml | 2 ++ src/registrar/config/settings.py | 7 +++++++ src/registrar/templates/application_purpose.html | 4 ++-- src/registrar/templatetags/url_helpers.py | 16 ++++++++++++++++ 7 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ops/manifests/manifest-stable.yaml b/ops/manifests/manifest-stable.yaml index 619e5fc7a..72726cd08 100644 --- a/ops/manifests/manifest-stable.yaml +++ b/ops/manifests/manifest-stable.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-stable.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # Public site base URL + GETGOV_PUBLIC_SITE_URL: https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/ routes: - route: getgov-stable.app.cloud.gov services: diff --git a/ops/scripts/manifest-sandbox-template.yaml b/ops/scripts/manifest-sandbox-template.yaml index ba814b3d5..1bf979c9f 100644 --- a/ops/scripts/manifest-sandbox-template.yaml +++ b/ops/scripts/manifest-sandbox-template.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-ENVIRONMENT.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # default public site location + GETGOV_PUBLIC_SITE_URL: https://beta.get.gov routes: - route: getgov-ENVIRONMENT.app.cloud.gov services: diff --git a/src/.env-example b/src/.env-example index 7100fc628..9b3f56409 100644 --- a/src/.env-example +++ b/src/.env-example @@ -1,2 +1,3 @@ DJANGO_SECRET_KEY="" DJANGO_SECRET_LOGIN_KEY="" +GETGOV_PUBLIC_SITE_URL="https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/" diff --git a/src/docker-compose.yml b/src/docker-compose.yml index 4399c5b70..8b1111868 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -27,6 +27,8 @@ services: - DJANGO_DEBUG=True # Tell Django where it is being hosted - DJANGO_BASE_URL=http://localhost:8080 + # Public site URL link + - GETGOV_PUBLIC_SITE_URL="https://beta.get.gov" # Set a username for accessing the registry - REGISTRY_CL_ID=nothing # Set a password for accessing the registry diff --git a/src/registrar/config/settings.py b/src/registrar/config/settings.py index 9491b354a..41559ceba 100644 --- a/src/registrar/config/settings.py +++ b/src/registrar/config/settings.py @@ -62,6 +62,9 @@ secret_registry_key = b64decode(secret("REGISTRY_KEY", "")) secret_registry_key_passphrase = secret("REGISTRY_KEY_PASSPHRASE", "") secret_registry_hostname = secret("REGISTRY_HOSTNAME") +# this needs to exist or a warning will be generated +secret_getgov_public_site_url = secret("GETGOV_PUBLIC_SITE_URL") + # region: Basic Django Config-----------------------------------------------### # Build paths inside the project like this: BASE_DIR / "subdir". @@ -503,6 +506,10 @@ ROOT_URLCONF = "registrar.config.urls" # Must be relative and end with "/" STATIC_URL = "public/" +# Base URL of our separate static public website. Used by the +# {% public_site_url subdir/path %} template tag +GETGOV_PUBLIC_SITE_URL = secret_getgov_public_site_url + # endregion # region: Registry----------------------------------------------------------### diff --git a/src/registrar/templates/application_purpose.html b/src/registrar/templates/application_purpose.html index a28dc27b3..ca2ff7287 100644 --- a/src/registrar/templates/application_purpose.html +++ b/src/registrar/templates/application_purpose.html @@ -1,5 +1,5 @@ {% extends 'application_form.html' %} -{% load field_helpers %} +{% load field_helpers url_helpers %} {% block form_instructions %}

.Gov domain names are for use on the internet. Don’t register a .gov to simply reserve a @@ -8,7 +8,7 @@ domain name or for mainly internal use.

Describe the reason for your domain request. Explain how you plan to use this domain. Who is your intended audience? Will you use it for a website and/or email? Are you moving your website from another top-level domain (like .com or .org)? -Read about activities that are prohibited on .gov domains.

+Read about activities that are prohibited on .gov domains.

{% endblock %} diff --git a/src/registrar/templatetags/url_helpers.py b/src/registrar/templatetags/url_helpers.py index 6201e61eb..7662a42d8 100644 --- a/src/registrar/templatetags/url_helpers.py +++ b/src/registrar/templatetags/url_helpers.py @@ -1,6 +1,10 @@ +from urllib.parse import urljoin + from django import template from django.urls import reverse +from django.conf import settings + register = template.Library() @@ -15,3 +19,15 @@ def startswith(text, starts): if isinstance(text, str): return text.startswith(starts) return False + + +@register.simple_tag +def public_site_url(url_path): + """Make a full URL for this path at our public site. + + The public site base url is set by a GETGOV_PUBLIC_SITE_URL environment + variable. + """ + base_url = settings.GETGOV_PUBLIC_SITE_URL + public_url = urljoin(base_url, url_path) + return public_url