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        description = "User-submitted support and feedback forms."
24        fields = ["user", "email", "name", "form_slug", "created_at"]
25
26    class DetailView(AdminModelDetailView):
27        model = SupportFormEntry
28
29
30class UserSupportFormEntriesCard(Card):
31    title = "Recent support"
32    template_name = "support/card.html"
33
34    def get_template_context(self) -> dict[str, Any]:
35        context = super().get_template_context()
36
37        # self.view has an object attribute when used in DetailView context
38        context["entries"] = SupportFormEntry.query.filter(
39            user=self.view.object  # type: ignore[attr-defined]
40        )
41
42        return context