From 4758b8bcfd5c5824e06e554f44872ad21248f3ac Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Mon, 6 Nov 2017 13:01:10 -0500 Subject: [PATCH] local_context_processors: Add host_url. This makes it easier for templates to generate a "single canonical URL" for a resource, as in Open Graph metadata. --- www/conservancy/local_context_processors.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/www/conservancy/local_context_processors.py b/www/conservancy/local_context_processors.py index 5bd2556a..c430d18d 100644 --- a/www/conservancy/local_context_processors.py +++ b/www/conservancy/local_context_processors.py @@ -1,3 +1,4 @@ +import conservancy.settings from conservancy.apps.fundgoal.models import FundraisingGoal as FundraisingGoal def fundgoal_lookup(fundraiser_sought): @@ -9,3 +10,11 @@ def fundgoal_lookup(fundraiser_sought): def sitefundraiser(request): return {'sitefundgoal': fundgoal_lookup('supporterrun') } + +if conservancy.settings.FORCE_CANONICAL_HOSTNAME: + _HOST_URL_VAR = {'host_url': 'https://' + conservancy.settings.FORCE_CANONICAL_HOSTNAME} + def host_url(request): + return _HOST_URL_VAR +else: + def host_url(request): + return {'host_url': request.build_absolute_uri('/').rstrip('/')}