cmsmanage/paperwork/dashboard.py

73 lines
2.1 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 = [
Link(
"Waivers",
reverse("paperwork:waivers-report"),
permission="paperwork.view_waiver",
),
Link(
"Instructors and Vendors",
reverse("paperwork:instructors-and-vendor-report"),
permission="paperwork.view_instructororvendor",
),
Link(
"Access Verification",
reverse("paperwork:access-verification-report"),
permission="paperwork.view_certification",
),
Link(
"Certifiers",
reverse("paperwork:certifiers-report"),
permission="paperwork.view_certification",
),
Link(
"Certification Count",
reverse("paperwork:certification-count-report"),
permission="paperwork.view_certification",
),
]
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