cmsmanage/paperwork/dashboard.py
2024-02-06 00:42:14 -05:00

47 lines
1.2 KiB
Python

from django.urls import reverse
import dashboard
from dashboard import Link
from membershipworks.models import Member
from .models import Department
@dashboard.register
class PaperworkDashboardFragment(dashboard.LinksCardDashboardFragment):
name = "Paperwork"
@property
def links(self) -> list[Link]:
links = []
member = Member.from_user(self.request.user)
if member is not None:
links.append(
dashboard.Link(
"Member Certifications",
reverse(
"paperwork:member_certifications", kwargs={"uid": member.uid}
),
permission=None,
)
)
if self.request.user.is_superuser or (
member is not None
and Department.objects.filter_by_shop_lead(member).exists()
):
links.append(
Link(
"Department Certifications",
reverse("paperwork:department_certifications"),
permission=None,
)
)
return links
@property
def visible(self) -> bool:
return self.request.user.is_authenticated