41 lines
756 B
Python
41 lines
756 B
Python
import dataclasses
|
|
from typing import Any
|
|
|
|
from django.http import HttpRequest
|
|
|
|
DASHBOARD_CARDS = {}
|
|
|
|
|
|
def register(fragment):
|
|
DASHBOARD_CARDS[fragment.name] = fragment
|
|
return fragment
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class Link:
|
|
text: str
|
|
href: str
|
|
tooltip: str | None = None
|
|
body: str | None = None
|
|
_: dataclasses.KW_ONLY
|
|
permission: str | None
|
|
|
|
|
|
class DashboardFragment:
|
|
name: str
|
|
template: str
|
|
context: Any = None
|
|
visible: bool = True
|
|
|
|
def __init__(self, request: HttpRequest):
|
|
self.request = request
|
|
|
|
|
|
class LinksCardDashboardFragment(DashboardFragment):
|
|
template = "dashboard/links_card.dj.html"
|
|
links: [Link] = []
|
|
|
|
@property
|
|
def context(self):
|
|
return {"links": self.links}
|