From b9f77251f1d0124ecd5a26f6e553b717a27caffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sat, 21 Jan 2023 16:20:50 +0100 Subject: [PATCH] Fix site context variable with a context processor. --- Makefile | 12 ++++-------- src/membership/views.py | 5 ++--- src/project/context_processors.py | 5 +++++ src/project/settings.py | 1 + src/utils/view_utils.py | 8 +------- 5 files changed, 13 insertions(+), 18 deletions(-) create mode 100644 src/project/context_processors.py diff --git a/Makefile b/Makefile index 9a8a731..2215ce7 100644 --- a/Makefile +++ b/Makefile @@ -23,10 +23,10 @@ pre_commit_run_all: venv/bin/pre-commit run --all-files makemigrations: - ${MANAGE_COMMAND} makemigrations ${EXTRA_ARGS} + ${MANAGE_COMMAND} makemigrations ${ARGS} migrate: - ${MANAGE_COMMAND} migrate ${EXTRA_ARGS} + ${MANAGE_COMMAND} migrate ${ARGS} createsuperuser: ${MANAGE_COMMAND} createsuperuser @@ -35,7 +35,7 @@ shell: ${MANAGE_COMMAND} shell manage_command: - ${MANAGE_COMMAND} ${COMMAND} + ${MANAGE_COMMAND} ${ARGS} add_dependency: ${DOCKER_RUN} ${DOCKER_CONTAINER_NAME} poetry add --lock ${DEPENDENCY} @@ -49,14 +49,10 @@ poetry_lock: poetry_command: ${DOCKER_RUN} ${DOCKER_CONTAINER_NAME} poetry ${COMMAND} -build_dev_docker_image: compile_requirements_dev +build_dev_docker_image: compile_requirements ${DOCKER_COMPOSE} build ${DOCKER_CONTAINER_NAME} compile_requirements: ./venv/bin/pip-compile --output-file requirements/base.txt requirements/base.in - -compile_requirements_test: compile_requirements ./venv/bin/pip-compile --output-file requirements/test.txt requirements/test.in - -compile_requirements_dev: compile_requirements_test ./venv/bin/pip-compile --output-file requirements/dev.txt requirements/dev.in diff --git a/src/membership/views.py b/src/membership/views.py index 03ae0f0..9b473f2 100644 --- a/src/membership/views.py +++ b/src/membership/views.py @@ -8,7 +8,6 @@ from .selectors import get_member from .selectors import get_members from .selectors import get_memberships from .selectors import get_subscription_periods -from utils.view_utils import base_view_context from utils.view_utils import render_list from utils.view_utils import RowAction @@ -21,7 +20,7 @@ def membership_overview(request): current_period = current_membership.period.period if current_membership else None - context = base_view_context(request) | { + context = { "current_membership": current_membership, "current_period": current_period, "previous_memberships": previous_memberships, @@ -66,7 +65,7 @@ def members_admin_detail(request, member_id): member = get_member(member_id=member_id) subscription_periods = get_subscription_periods(member=member) - context = base_view_context(request) | { + context = { "member": member, "subscription_periods": subscription_periods, } diff --git a/src/project/context_processors.py b/src/project/context_processors.py new file mode 100644 index 0000000..05e37ed --- /dev/null +++ b/src/project/context_processors.py @@ -0,0 +1,5 @@ +from django.contrib.sites.shortcuts import get_current_site + + +def current_site(request): + return {"site": get_current_site(request)} diff --git a/src/project/settings.py b/src/project/settings.py index 6bcac24..f04d367 100644 --- a/src/project/settings.py +++ b/src/project/settings.py @@ -80,6 +80,7 @@ TEMPLATES = [ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", + "project.context_processors.current_site", ], }, }, diff --git a/src/utils/view_utils.py b/src/utils/view_utils.py index 9b5b277..e516f28 100644 --- a/src/utils/view_utils.py +++ b/src/utils/view_utils.py @@ -1,7 +1,6 @@ import contextlib from dataclasses import dataclass -from django.contrib.sites.shortcuts import get_current_site as django_get_current_site from django.core.exceptions import FieldError from django.core.paginator import Paginator from django.db.models import Model @@ -11,11 +10,6 @@ from django.urls import reverse from zen_queries import render -def base_view_context(request): - """Include the current site in the context.""" - return {"site": django_get_current_site(request)} - - @dataclass class Row: """ @@ -82,7 +76,7 @@ def render_list( ) rows.append(row) - context = base_view_context(request) | { + context = { "rows": rows, "columns": columns, "row_actions": row_actions,