django-helpdeskmig/helpdesk/admin.py

143 lines
4.0 KiB
Python
Raw Normal View History

from django.contrib import admin
2022-03-17 03:29:09 +01:00
from django.utils.translation import gettext_lazy as _
2022-03-18 19:21:17 +01:00
from helpdesk import settings as helpdesk_settings
from helpdesk.models import (
2023-04-30 04:13:50 +02:00
Checklist,
ChecklistTask,
ChecklistTemplate,
CustomField,
EmailTemplate,
EscalationExclusion,
FollowUp,
FollowUpAttachment,
IgnoreEmail,
KBIAttachment,
PreSetReply,
Queue,
Ticket,
2023-04-30 04:13:50 +02:00
TicketChange
)
2022-03-18 19:21:17 +01:00
if helpdesk_settings.HELPDESK_KB_ENABLED:
from helpdesk.models import KBCategory, KBItem
2016-10-21 17:14:12 +02:00
2022-07-12 12:34:19 +02:00
2016-10-21 17:14:12 +02:00
@admin.register(Queue)
class QueueAdmin(admin.ModelAdmin):
list_display = ('title', 'slug', 'email_address', 'locale', 'time_spent')
prepopulated_fields = {"slug": ("title",)}
def time_spent(self, q):
if q.dedicated_time:
return "{} / {}".format(q.time_spent, q.dedicated_time)
elif q.time_spent:
return q.time_spent
else:
return "-"
2016-10-21 17:14:12 +02:00
@admin.register(Ticket)
class TicketAdmin(admin.ModelAdmin):
list_display = ('title', 'status', 'assigned_to', 'queue',
'hidden_submitter_email', 'time_spent')
date_hierarchy = 'created'
list_filter = ('queue', 'assigned_to', 'status')
2023-04-22 22:55:41 +02:00
search_fields = ('id', 'title')
def hidden_submitter_email(self, ticket):
if ticket.submitter_email:
username, domain = ticket.submitter_email.split("@")
username = username[:2] + "*" * (len(username) - 2)
domain = domain[:1] + "*" * (len(domain) - 2) + domain[-1:]
return "%s@%s" % (username, domain)
else:
return ticket.submitter_email
hidden_submitter_email.short_description = _('Submitter E-Mail')
def time_spent(self, ticket):
return ticket.time_spent
2016-10-21 17:14:12 +02:00
class TicketChangeInline(admin.StackedInline):
model = TicketChange
extra = 0
2016-10-21 17:14:12 +02:00
class FollowUpAttachmentInline(admin.StackedInline):
model = FollowUpAttachment
extra = 0
class KBIAttachmentInline(admin.StackedInline):
model = KBIAttachment
extra = 0
2016-10-21 17:14:12 +02:00
@admin.register(FollowUp)
class FollowUpAdmin(admin.ModelAdmin):
inlines = [TicketChangeInline, FollowUpAttachmentInline]
list_display = ('ticket_get_ticket_for_url', 'title', 'date', 'ticket',
'user', 'new_status', 'time_spent')
list_filter = ('user', 'date', 'new_status')
def ticket_get_ticket_for_url(self, obj):
return obj.ticket.ticket_for_url
ticket_get_ticket_for_url.short_description = _('Slug')
2016-10-21 17:14:12 +02:00
2022-03-18 19:21:17 +01:00
if helpdesk_settings.HELPDESK_KB_ENABLED:
@admin.register(KBItem)
class KBItemAdmin(admin.ModelAdmin):
2022-07-12 12:34:19 +02:00
list_display = ('category', 'title', 'last_updated',
'team', 'order', 'enabled')
2022-03-18 19:21:17 +01:00
inlines = [KBIAttachmentInline]
readonly_fields = ('voted_by', 'downvoted_by')
list_display_links = ('title',)
if helpdesk_settings.HELPDESK_KB_ENABLED:
@admin.register(KBCategory)
class KBCategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'title', 'slug', 'public')
2016-10-21 17:14:12 +02:00
@admin.register(CustomField)
class CustomFieldAdmin(admin.ModelAdmin):
list_display = ('name', 'label', 'data_type')
2016-10-21 17:14:12 +02:00
@admin.register(EmailTemplate)
class EmailTemplateAdmin(admin.ModelAdmin):
list_display = ('template_name', 'heading', 'locale')
list_filter = ('locale', )
@admin.register(IgnoreEmail)
class IgnoreEmailAdmin(admin.ModelAdmin):
list_display = ('name', 'queue_list', 'email_address', 'keep_in_mailbox')
2023-04-22 22:55:41 +02:00
@admin.register(ChecklistTemplate)
class ChecklistTemplateAdmin(admin.ModelAdmin):
list_display = ('name', 'task_list')
search_fields = ('name', 'task_list')
class ChecklistTaskInline(admin.TabularInline):
model = ChecklistTask
@admin.register(Checklist)
class ChecklistAdmin(admin.ModelAdmin):
list_display = ('name', 'ticket')
search_fields = ('name', 'ticket__id', 'ticket__title')
autocomplete_fields = ('ticket',)
list_select_related = ('ticket',)
inlines = (ChecklistTaskInline,)
admin.site.register(PreSetReply)
admin.site.register(EscalationExclusion)