Move SITE_FUNDGOAL configuration to settings/base.py

This changes more often than the surrounding code, so should live with the other
configuration.
This commit is contained in:
Ben Sturmfels 2024-05-10 12:00:44 +10:00
parent 1792c7ed8b
commit 0b8ae2ca77
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
5 changed files with 19 additions and 25 deletions

View file

@ -10,6 +10,7 @@
# Done # Done
* move `SITE_FUNDGOAL` configuration to `settings.py`
* move `sponsors.py` and `sponsors.html` into `supporters` app * move `sponsors.py` and `sponsors.html` into `supporters` app
* use `<detail>` elements for supporter page hidden sections, rather than * use `<detail>` elements for supporter page hidden sections, rather than
complex jQuery complex jQuery

View file

@ -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('/')}

View file

@ -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('/')}

View file

@ -111,8 +111,8 @@ TEMPLATES = [
'django.template.context_processors.request', 'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
'conservancy.local_context_processors.host_url', 'conservancy.context_processors.host_url',
'conservancy.local_context_processors.sitefundraiser', 'conservancy.context_processors.sitefundraiser',
] ]
} }
} }
@ -143,3 +143,5 @@ USETHESOURCE = {
'SENDER': 'compliance@sfconservancy.org', 'SENDER': 'compliance@sfconservancy.org',
'LIST_RECIPIENT': 'ccs-review@lists.sfconservancy.org', 'LIST_RECIPIENT': 'ccs-review@lists.sfconservancy.org',
} }
SITE_FUNDGOAL = 'cy2023-end-year-match'

View file

@ -7,7 +7,6 @@ from django.shortcuts import render
from django.template import RequestContext, Template from django.template import RequestContext, Template
from .blog.models import Entry from .blog.models import Entry
from .local_context_processors import fundgoal_lookup
from .news.models import PressRelease from .news.models import PressRelease
from .supporters.models import Supporter from .supporters.models import Supporter
@ -62,10 +61,6 @@ def content(request, *args, **kwargs):
if not is_template: if not is_template:
return FileResponse(open(full_path, 'rb')) return FileResponse(open(full_path, 'rb'))
else: else:
try:
kwargs['fundgoal'] = fundgoal_lookup(kwargs['fundraiser_sought'])
except KeyError:
pass
# These template are intentionally not in the template loader path, so # These template are intentionally not in the template loader path, so
# we open them directly, rather than using the template loader. # we open them directly, rather than using the template loader.
with open(full_path, encoding='utf-8') as t: with open(full_path, encoding='utf-8') as t: