diff --git a/TODO.md b/TODO.md index 5dbd27d9..c58eba5c 100644 --- a/TODO.md +++ b/TODO.md @@ -10,6 +10,7 @@ # Done +* move `SITE_FUNDGOAL` configuration to `settings.py` * move `sponsors.py` and `sponsors.html` into `supporters` app * use `` elements for supporter page hidden sections, rather than complex jQuery diff --git a/conservancy/context_processors.py b/conservancy/context_processors.py new file mode 100644 index 00000000..9cfd1644 --- /dev/null +++ b/conservancy/context_processors.py @@ -0,0 +1,14 @@ +from django.conf import settings + +from .fundgoal.models import FundraisingGoal + +def sitefundraiser(request): + try: + fundgoal = FundraisingGoal.objects.get(fundraiser_code_name=settings.SITE_FUNDGOAL) + except FundraisingGoal.DoesNotExist: + fundgoal = None + return {'sitefundgoal': fundgoal} + + +def host_url(request): + return {'host_url': request.build_absolute_uri('/').rstrip('/')} diff --git a/conservancy/local_context_processors.py b/conservancy/local_context_processors.py deleted file mode 100644 index 003a1eeb..00000000 --- a/conservancy/local_context_processors.py +++ /dev/null @@ -1,18 +0,0 @@ -from .fundgoal.models import FundraisingGoal - -SITE_FUNDGOAL = 'cy2023-end-year-match' - -def fundgoal_lookup(fundraiser_sought): - try: - return FundraisingGoal.objects.get(fundraiser_code_name=fundraiser_sought) - except FundraisingGoal.DoesNotExist: - # we have no object! do something - return None - -def sitefundraiser(request): - return { - 'sitefundgoal': fundgoal_lookup(SITE_FUNDGOAL), - } - -def host_url(request): - return {'host_url': request.build_absolute_uri('/').rstrip('/')} diff --git a/conservancy/settings/base.py b/conservancy/settings/base.py index bfc52016..df81f8a0 100644 --- a/conservancy/settings/base.py +++ b/conservancy/settings/base.py @@ -111,8 +111,8 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', - 'conservancy.local_context_processors.host_url', - 'conservancy.local_context_processors.sitefundraiser', + 'conservancy.context_processors.host_url', + 'conservancy.context_processors.sitefundraiser', ] } } @@ -143,3 +143,5 @@ USETHESOURCE = { 'SENDER': 'compliance@sfconservancy.org', 'LIST_RECIPIENT': 'ccs-review@lists.sfconservancy.org', } + +SITE_FUNDGOAL = 'cy2023-end-year-match' diff --git a/conservancy/views.py b/conservancy/views.py index 5509b387..cbc1dd46 100644 --- a/conservancy/views.py +++ b/conservancy/views.py @@ -7,7 +7,6 @@ from django.shortcuts import render from django.template import RequestContext, Template from .blog.models import Entry -from .local_context_processors import fundgoal_lookup from .news.models import PressRelease from .supporters.models import Supporter @@ -62,10 +61,6 @@ def content(request, *args, **kwargs): if not is_template: return FileResponse(open(full_path, 'rb')) else: - try: - kwargs['fundgoal'] = fundgoal_lookup(kwargs['fundraiser_sought']) - except KeyError: - pass # These template are intentionally not in the template loader path, so # we open them directly, rather than using the template loader. with open(full_path, encoding='utf-8') as t: