1from __future__ import annotations
2
3from typing import Any
4
5from plain.admin.cards import Card
6from plain.admin.views import (
7 AdminModelDetailView,
8 AdminModelListView,
9 AdminViewset,
10 register_viewset,
11)
12
13from .models import SupportFormEntry
14
15
16@register_viewset
17class SupportFormEntryAdmin(AdminViewset):
18 class ListView(AdminModelListView):
19 model = SupportFormEntry
20 nav_section = "Support"
21 nav_icon = "headset"
22 title = "Form entries"
23 fields = ["user", "email", "name", "form_slug", "created_at"]
24
25 class DetailView(AdminModelDetailView):
26 model = SupportFormEntry
27
28
29class UserSupportFormEntriesCard(Card):
30 title = "Recent support"
31 template_name = "support/card.html"
32
33 def get_template_context(self) -> dict[str, Any]:
34 context = super().get_template_context()
35
36 # self.view has an object attribute when used in DetailView context
37 context["entries"] = SupportFormEntry.query.filter(
38 user=self.view.object # type: ignore[attr-defined]
39 )
40
41 return context