mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 12:08:40 +02:00
Merge pull request #625 from cisagov/nmb/612-public-site
Add public site helper tag for Django site
This commit is contained in:
commit
3780b64174
15 changed files with 76 additions and 2 deletions
|
@ -20,6 +20,8 @@ applications:
|
||||||
DJANGO_BASE_URL: https://getgov-ab.app.cloud.gov
|
DJANGO_BASE_URL: https://getgov-ab.app.cloud.gov
|
||||||
# Tell Django how much stuff to log
|
# Tell Django how much stuff to log
|
||||||
DJANGO_LOG_LEVEL: INFO
|
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:
|
routes:
|
||||||
- route: getgov-ab.app.cloud.gov
|
- route: getgov-ab.app.cloud.gov
|
||||||
services:
|
services:
|
||||||
|
|
|
@ -20,6 +20,8 @@ applications:
|
||||||
DJANGO_BASE_URL: https://getgov-bl.app.cloud.gov
|
DJANGO_BASE_URL: https://getgov-bl.app.cloud.gov
|
||||||
# Tell Django how much stuff to log
|
# Tell Django how much stuff to log
|
||||||
DJANGO_LOG_LEVEL: INFO
|
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:
|
routes:
|
||||||
- route: getgov-bl.app.cloud.gov
|
- route: getgov-bl.app.cloud.gov
|
||||||
services:
|
services:
|
||||||
|
|
|
@ -20,6 +20,8 @@ applications:
|
||||||
DJANGO_BASE_URL: https://getgov-ik.app.cloud.gov
|
DJANGO_BASE_URL: https://getgov-ik.app.cloud.gov
|
||||||
# Tell Django how much stuff to log
|
# Tell Django how much stuff to log
|
||||||
DJANGO_LOG_LEVEL: INFO
|
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:
|
routes:
|
||||||
- route: getgov-ik.app.cloud.gov
|
- route: getgov-ik.app.cloud.gov
|
||||||
services:
|
services:
|
||||||
|
|
|
@ -20,6 +20,8 @@ applications:
|
||||||
DJANGO_BASE_URL: https://getgov-jon.app.cloud.gov
|
DJANGO_BASE_URL: https://getgov-jon.app.cloud.gov
|
||||||
# Tell Django how much stuff to log
|
# Tell Django how much stuff to log
|
||||||
DJANGO_LOG_LEVEL: INFO
|
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:
|
routes:
|
||||||
- route: getgov-jon.app.cloud.gov
|
- route: getgov-jon.app.cloud.gov
|
||||||
services:
|
services:
|
||||||
|
|
|
@ -20,6 +20,8 @@ applications:
|
||||||
DJANGO_BASE_URL: https://getgov-mr.app.cloud.gov
|
DJANGO_BASE_URL: https://getgov-mr.app.cloud.gov
|
||||||
# Tell Django how much stuff to log
|
# Tell Django how much stuff to log
|
||||||
DJANGO_LOG_LEVEL: INFO
|
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:
|
routes:
|
||||||
- route: getgov-mr.app.cloud.gov
|
- route: getgov-mr.app.cloud.gov
|
||||||
services:
|
services:
|
||||||
|
|
|
@ -20,6 +20,8 @@ applications:
|
||||||
DJANGO_BASE_URL: https://getgov-nmb.app.cloud.gov
|
DJANGO_BASE_URL: https://getgov-nmb.app.cloud.gov
|
||||||
# Tell Django how much stuff to log
|
# Tell Django how much stuff to log
|
||||||
DJANGO_LOG_LEVEL: INFO
|
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:
|
routes:
|
||||||
- route: getgov-nmb.app.cloud.gov
|
- route: getgov-nmb.app.cloud.gov
|
||||||
services:
|
services:
|
||||||
|
|
|
@ -20,6 +20,8 @@ applications:
|
||||||
DJANGO_BASE_URL: https://getgov-rjm.app.cloud.gov
|
DJANGO_BASE_URL: https://getgov-rjm.app.cloud.gov
|
||||||
# Tell Django how much stuff to log
|
# Tell Django how much stuff to log
|
||||||
DJANGO_LOG_LEVEL: INFO
|
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:
|
routes:
|
||||||
- route: getgov-rjm.app.cloud.gov
|
- route: getgov-rjm.app.cloud.gov
|
||||||
services:
|
services:
|
||||||
|
|
|
@ -20,6 +20,8 @@ applications:
|
||||||
DJANGO_BASE_URL: https://getgov-sspj.app.cloud.gov
|
DJANGO_BASE_URL: https://getgov-sspj.app.cloud.gov
|
||||||
# Tell Django how much stuff to log
|
# Tell Django how much stuff to log
|
||||||
DJANGO_LOG_LEVEL: INFO
|
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:
|
routes:
|
||||||
- route: getgov-sspj.app.cloud.gov
|
- route: getgov-sspj.app.cloud.gov
|
||||||
services:
|
services:
|
||||||
|
|
|
@ -20,6 +20,8 @@ applications:
|
||||||
DJANGO_BASE_URL: https://getgov-stable.app.cloud.gov
|
DJANGO_BASE_URL: https://getgov-stable.app.cloud.gov
|
||||||
# Tell Django how much stuff to log
|
# Tell Django how much stuff to log
|
||||||
DJANGO_LOG_LEVEL: INFO
|
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:
|
routes:
|
||||||
- route: getgov-stable.app.cloud.gov
|
- route: getgov-stable.app.cloud.gov
|
||||||
services:
|
services:
|
||||||
|
|
|
@ -20,6 +20,8 @@ applications:
|
||||||
DJANGO_BASE_URL: https://getgov-ENVIRONMENT.app.cloud.gov
|
DJANGO_BASE_URL: https://getgov-ENVIRONMENT.app.cloud.gov
|
||||||
# Tell Django how much stuff to log
|
# Tell Django how much stuff to log
|
||||||
DJANGO_LOG_LEVEL: INFO
|
DJANGO_LOG_LEVEL: INFO
|
||||||
|
# default public site location
|
||||||
|
GETGOV_PUBLIC_SITE_URL: https://beta.get.gov
|
||||||
routes:
|
routes:
|
||||||
- route: getgov-ENVIRONMENT.app.cloud.gov
|
- route: getgov-ENVIRONMENT.app.cloud.gov
|
||||||
services:
|
services:
|
||||||
|
|
|
@ -27,6 +27,8 @@ services:
|
||||||
- DJANGO_DEBUG=True
|
- DJANGO_DEBUG=True
|
||||||
# Tell Django where it is being hosted
|
# Tell Django where it is being hosted
|
||||||
- DJANGO_BASE_URL=http://localhost:8080
|
- 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
|
# Set a username for accessing the registry
|
||||||
- REGISTRY_CL_ID=nothing
|
- REGISTRY_CL_ID=nothing
|
||||||
# Set a password for accessing the registry
|
# Set a password for accessing the registry
|
||||||
|
|
|
@ -62,6 +62,8 @@ secret_registry_key = b64decode(secret("REGISTRY_KEY", ""))
|
||||||
secret_registry_key_passphrase = secret("REGISTRY_KEY_PASSPHRASE", "")
|
secret_registry_key_passphrase = secret("REGISTRY_KEY_PASSPHRASE", "")
|
||||||
secret_registry_hostname = secret("REGISTRY_HOSTNAME")
|
secret_registry_hostname = secret("REGISTRY_HOSTNAME")
|
||||||
|
|
||||||
|
secret_getgov_public_site_url = secret("GETGOV_PUBLIC_SITE_URL", "")
|
||||||
|
|
||||||
# region: Basic Django Config-----------------------------------------------###
|
# region: Basic Django Config-----------------------------------------------###
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / "subdir".
|
# Build paths inside the project like this: BASE_DIR / "subdir".
|
||||||
|
@ -505,6 +507,10 @@ ROOT_URLCONF = "registrar.config.urls"
|
||||||
# Must be relative and end with "/"
|
# Must be relative and end with "/"
|
||||||
STATIC_URL = "public/"
|
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
|
# endregion
|
||||||
# region: Registry----------------------------------------------------------###
|
# region: Registry----------------------------------------------------------###
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% extends 'application_form.html' %}
|
{% extends 'application_form.html' %}
|
||||||
{% load field_helpers %}
|
{% load field_helpers url_helpers %}
|
||||||
|
|
||||||
{% block form_instructions %}
|
{% block form_instructions %}
|
||||||
<p>.Gov domain names are for use on the internet. Don’t register a .gov to simply reserve a
|
<p>.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.</p>
|
||||||
<p>Describe the reason for your domain request. Explain how you plan to use this domain.
|
<p>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
|
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)?
|
your website from another top-level domain (like .com or .org)?
|
||||||
Read about <a href="{% url 'todo' %}">activities that are prohibited on .gov domains.</a></p>
|
Read about <a href="{% public_site_url 'domains/requirements/' %}">activities that are prohibited on .gov domains.</a></p>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from django import template
|
from django import template
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,3 +17,16 @@ def startswith(text, starts):
|
||||||
if isinstance(text, str):
|
if isinstance(text, str):
|
||||||
return text.startswith(starts)
|
return text.startswith(starts)
|
||||||
return False
|
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
|
||||||
|
# join the two halves with a single slash
|
||||||
|
public_url = "/".join([base_url.rstrip("/"), url_path.lstrip("/")])
|
||||||
|
return public_url
|
||||||
|
|
31
src/registrar/tests/test_templatetags.py
Normal file
31
src/registrar/tests/test_templatetags.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
"""Test template tags."""
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.template import Context, Template
|
||||||
|
|
||||||
|
|
||||||
|
class TestTemplateTags(TestCase):
|
||||||
|
def _render_template(self, string, context=None):
|
||||||
|
"""Helper method to render a template given as a string.
|
||||||
|
|
||||||
|
Originally from https://stackoverflow.com/a/1690879
|
||||||
|
"""
|
||||||
|
context = context or {}
|
||||||
|
context = Context(context)
|
||||||
|
return Template(string).render(context)
|
||||||
|
|
||||||
|
def test_public_site_url(self):
|
||||||
|
result = self._render_template(
|
||||||
|
"{% load url_helpers %}{% public_site_url 'directory/page' %}"
|
||||||
|
)
|
||||||
|
self.assertTrue(result.startswith(settings.GETGOV_PUBLIC_SITE_URL))
|
||||||
|
self.assertTrue(result.endswith("/directory/page"))
|
||||||
|
|
||||||
|
def test_public_site_url_leading_slash(self):
|
||||||
|
result = self._render_template(
|
||||||
|
"{% load url_helpers %}{% public_site_url '/directory/page' %}"
|
||||||
|
)
|
||||||
|
self.assertTrue(result.startswith(settings.GETGOV_PUBLIC_SITE_URL))
|
||||||
|
# slash-slash host slash directory slash page
|
||||||
|
self.assertEqual(result.count("/"), 4)
|
Loading…
Add table
Add a link
Reference in a new issue