Small adjustments.

This commit is contained in:
Víðir Valberg Guðmundsson 2023-09-30 08:14:02 +02:00
parent 770c1c81b6
commit d2e58d396f
6 changed files with 45 additions and 32 deletions

View file

@ -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)

View file

@ -3,7 +3,6 @@
{% block content %}
<h1>
{{ member.username }}
</h1>
@ -12,28 +11,29 @@
<h3>{% trans "Membership" %}</h3>
<table class="table">
<thead>
<tr>
<th>{% trans "Start" %}</th>
<th>{% trans "End" %}</th>
<th>{% trans "Has membership" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
</thead>
<tbody>
{% for period in subscription_periods %}
<tr {% if not period.period.upper %}class="table-active"{% endif %}>
<td>{{ period.period.lower }}</td>
<td>{{ period.period.upper }}</td>
<td>{{ period.membership_exists }}</td>
<td></td>
{% if subscription_periods %}
<table class="table">
<thead>
<tr>
<th>{% trans "Start" %}</th>
<th>{% trans "End" %}</th>
<th>{% trans "Has membership" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
{% endfor %}
</tbody>
</table>
</thead>
<tbody>
{% for period in subscription_periods %}
<tr {% if not period.period.upper %}class="table-active"{% endif %}>
<td>{{ period.period.lower }}</td>
<td>{{ period.period.upper }}</td>
<td>{{ period.membership_exists }}</td>
<td></td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
{% trans "No memberships" %}
{% endif %}
{% endblock %}

View file

@ -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

View file

@ -1,5 +0,0 @@
from django.contrib.sites.shortcuts import get_current_site
def current_site(request):
return {"site": get_current_site(request)}

View file

@ -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",
],
},
},

View file

@ -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)