membersystem/src/membership/views.py

46 lines
1.3 KiB
Python
Raw Normal View History

from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import permission_required
from zen_queries import render
from .permissions import ADMINISTRATE_MEMBERSHIPS
from .selectors import get_memberships
from .selectors import get_subscription_periods
from utils.view_utils import base_view_context
@login_required
def membership_overview(request):
memberships = get_memberships(user=request.user)
current_membership = memberships.current()
previous_memberships = memberships.previous()
2023-01-02 21:13:25 +00:00
current_period = current_membership.period.period if current_membership else None
context = base_view_context(request) | {
2022-08-09 12:39:02 +00:00
"current_membership": current_membership,
2023-01-02 21:13:25 +00:00
"current_period": current_period,
2022-08-09 12:39:02 +00:00
"previous_memberships": previous_memberships,
}
2023-01-02 21:13:25 +00:00
return render(
request=request,
template_name="membership/membership_overview.html",
context=context,
)
@login_required
@permission_required(ADMINISTRATE_MEMBERSHIPS.path)
def membership_admin(request):
subscription_periods = get_subscription_periods()
context = base_view_context(request) | {
"subscription_periods": subscription_periods,
}
return render(
request=request,
template_name="membership/membership_admin.html",
2023-01-02 21:13:25 +00:00
context=context,
)