diff --git a/src/membership/selectors.py b/src/membership/selectors.py
index 21a8326..83458b3 100644
--- a/src/membership/selectors.py
+++ b/src/membership/selectors.py
@@ -23,7 +23,7 @@ def get_subscription_periods(member: Member | None = None) -> list[SubscriptionP
period=OuterRef("pk"),
),
),
- )
+ ).filter(membership_exists=True)
return list(subscription_periods)
diff --git a/src/membership/templates/membership/members_admin_detail.html b/src/membership/templates/membership/members_admin_detail.html
index 429c215..87a6235 100644
--- a/src/membership/templates/membership/members_admin_detail.html
+++ b/src/membership/templates/membership/members_admin_detail.html
@@ -3,7 +3,6 @@
{% block content %}
-
{{ member.username }}
@@ -12,28 +11,29 @@
{% trans "Membership" %}
-
-
-
- {% trans "Start" %} |
- {% trans "End" %} |
- {% trans "Has membership" %} |
- {% trans "Actions" %} |
-
-
-
- {% for period in subscription_periods %}
-
- {{ period.period.lower }} |
- {{ period.period.upper }} |
- {{ period.membership_exists }} |
- |
+ {% if subscription_periods %}
+
+
+
+ {% trans "Start" %} |
+ {% trans "End" %} |
+ {% trans "Has membership" %} |
+ {% trans "Actions" %} |
- {% endfor %}
-
-
-
-
-
+
+
+ {% for period in subscription_periods %}
+
+ {{ period.period.lower }} |
+ {{ period.period.upper }} |
+ {{ period.membership_exists }} |
+ |
+
+ {% endfor %}
+
+
+ {% else %}
+ {% trans "No memberships" %}
+ {% endif %}
{% endblock %}
diff --git a/src/membership/views.py b/src/membership/views.py
index ad0bf9f..e20f43f 100644
--- a/src/membership/views.py
+++ b/src/membership/views.py
@@ -1,13 +1,13 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import permission_required
from django.utils.translation import gettext_lazy as _
-from zen_queries import render
from .permissions import ADMINISTRATE_MEMBERS
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 render
from utils.view_utils import render_list
from utils.view_utils import RowAction
diff --git a/src/project/context_processors.py b/src/project/context_processors.py
deleted file mode 100644
index 05e37ed..0000000
--- a/src/project/context_processors.py
+++ /dev/null
@@ -1,5 +0,0 @@
-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 c14eca6..12ed44e 100644
--- a/src/project/settings.py
+++ b/src/project/settings.py
@@ -81,7 +81,6 @@ 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 1c90922..535086b 100644
--- a/src/utils/view_utils.py
+++ b/src/utils/view_utils.py
@@ -1,14 +1,16 @@
import contextlib
from dataclasses import dataclass
+from typing import Any
+from django.contrib.sites.shortcuts import get_current_site
from django.core.exceptions import FieldError
from django.core.paginator import Paginator
from django.db.models import Model
from django.http import HttpRequest
from django.http import HttpResponse
-from django.shortcuts import render
from django.urls import reverse
from zen_queries import queries_disabled
+from zen_queries import render as zen_queries_render
@dataclass
@@ -98,3 +100,20 @@ def render_list(
template_name="utils/list.html",
context=context,
)
+
+
+def base_context(request: HttpRequest) -> dict[str, Any]:
+ """
+ Return a base context for all views.
+ """
+ return {"site": get_current_site(request)}
+
+
+def render(request, template_name, context=None):
+ """
+ Render a template with a base context.
+ """
+ if context is None:
+ context = {}
+ context = base_context(request) | context
+ return zen_queries_render(request, template_name, context)