NDOJ/judge/admin/ticket.py

60 lines
1.6 KiB
Python
Raw Permalink Normal View History

2020-01-21 06:35:58 +00:00
from django.contrib.admin import ModelAdmin
from django.contrib.admin.options import StackedInline
from django.forms import ModelForm
from django.urls import reverse_lazy
from judge.models import TicketMessage
2022-05-14 17:57:27 +00:00
from judge.widgets import (
AdminHeavySelect2MultipleWidget,
AdminHeavySelect2Widget,
HeavyPreviewAdminPageDownWidget,
)
2020-01-21 06:35:58 +00:00
class TicketMessageForm(ModelForm):
class Meta:
widgets = {
2022-05-14 17:57:27 +00:00
"user": AdminHeavySelect2Widget(
data_view="profile_select2", attrs={"style": "width: 100%"}
),
2020-01-21 06:35:58 +00:00
}
if HeavyPreviewAdminPageDownWidget is not None:
2022-05-14 17:57:27 +00:00
widgets["body"] = HeavyPreviewAdminPageDownWidget(
preview=reverse_lazy("ticket_preview")
)
2020-01-21 06:35:58 +00:00
class TicketMessageInline(StackedInline):
model = TicketMessage
form = TicketMessageForm
2022-05-14 17:57:27 +00:00
fields = ("user", "body")
2020-01-21 06:35:58 +00:00
class TicketForm(ModelForm):
class Meta:
widgets = {
2022-05-14 17:57:27 +00:00
"user": AdminHeavySelect2Widget(
data_view="profile_select2", attrs={"style": "width: 100%"}
),
"assignees": AdminHeavySelect2MultipleWidget(
data_view="profile_select2", attrs={"style": "width: 100%"}
),
2020-01-21 06:35:58 +00:00
}
class TicketAdmin(ModelAdmin):
2022-05-14 17:57:27 +00:00
fields = (
"title",
"time",
"user",
"assignees",
"content_type",
"object_id",
"notes",
)
readonly_fields = ("time",)
list_display = ("title", "user", "time", "linked_item")
2020-01-21 06:35:58 +00:00
inlines = [TicketMessageInline]
form = TicketForm
2022-05-14 17:57:27 +00:00
date_hierarchy = "time"