2021-02-28 22:00:11 +00:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2023-01-02 22:06:00 +00:00
|
|
|
from django.contrib.auth.decorators import permission_required
|
2023-01-03 16:00:07 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2023-01-02 22:06:00 +00:00
|
|
|
from zen_queries import render
|
2021-02-28 22:00:11 +00:00
|
|
|
|
2023-01-03 16:00:07 +00:00
|
|
|
from .permissions import ADMINISTRATE_MEMBERS
|
2023-01-02 22:06:00 +00:00
|
|
|
from .selectors import get_memberships
|
2023-01-03 16:00:07 +00:00
|
|
|
from .selectors import get_users
|
2023-01-02 22:06:00 +00:00
|
|
|
from utils.view_utils import base_view_context
|
2023-01-03 16:00:07 +00:00
|
|
|
from utils.view_utils import render_list
|
2021-02-28 22:00:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def membership_overview(request):
|
2023-01-02 22:06:00 +00:00
|
|
|
memberships = get_memberships(user=request.user)
|
2021-02-28 22:00:11 +00:00
|
|
|
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
|
|
|
|
|
2023-01-02 22:06:00 +00:00
|
|
|
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,
|
|
|
|
}
|
2021-02-28 22:00:11 +00:00
|
|
|
|
2023-01-02 21:13:25 +00:00
|
|
|
return render(
|
|
|
|
request=request,
|
2023-01-02 22:06:00 +00:00
|
|
|
template_name="membership/membership_overview.html",
|
|
|
|
context=context,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2023-01-03 16:00:07 +00:00
|
|
|
@permission_required(ADMINISTRATE_MEMBERS.path)
|
|
|
|
def members_admin(request):
|
|
|
|
users = get_users()
|
2023-01-02 22:06:00 +00:00
|
|
|
|
2023-01-03 16:00:07 +00:00
|
|
|
return render_list(
|
2023-01-02 22:06:00 +00:00
|
|
|
request=request,
|
2023-01-03 16:00:07 +00:00
|
|
|
objects=users,
|
|
|
|
columns=[
|
|
|
|
("username", _("Username")),
|
|
|
|
("first_name", _("First name")),
|
|
|
|
("last_name", _("Last name")),
|
|
|
|
("email", _("Email")),
|
|
|
|
],
|
2023-01-02 21:13:25 +00:00
|
|
|
)
|