2024-02-06 00:41:01 -05:00
|
|
|
import dataclasses
|
2023-04-14 01:24:36 -04:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from django.http import HttpRequest
|
|
|
|
|
|
|
|
DASHBOARD_CARDS = {}
|
|
|
|
|
|
|
|
|
|
|
|
def register(fragment):
|
|
|
|
DASHBOARD_CARDS[fragment.name] = fragment
|
|
|
|
return fragment
|
|
|
|
|
|
|
|
|
2024-02-06 00:41:01 -05:00
|
|
|
@dataclasses.dataclass
|
|
|
|
class Link:
|
|
|
|
text: str
|
|
|
|
href: str
|
|
|
|
tooltip: str | None = None
|
|
|
|
body: str | None = None
|
|
|
|
_: dataclasses.KW_ONLY
|
|
|
|
permission: str | None
|
|
|
|
|
|
|
|
|
2023-04-14 01:24:36 -04:00
|
|
|
class DashboardFragment:
|
|
|
|
name: str
|
|
|
|
template: str
|
|
|
|
context: Any = None
|
|
|
|
visible: bool = True
|
|
|
|
|
|
|
|
def __init__(self, request: HttpRequest):
|
|
|
|
self.request = request
|
2024-02-06 00:41:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
class LinksCardDashboardFragment(DashboardFragment):
|
|
|
|
template = "dashboard/links_card.dj.html"
|
|
|
|
links: [Link] = []
|
|
|
|
|
|
|
|
@property
|
|
|
|
def context(self):
|
|
|
|
return {"links": self.links}
|