204 lines
5.9 KiB
Python
204 lines
5.9 KiB
Python
"""
|
|
Appreciation admin configuration
|
|
"""
|
|
from django.contrib import admin
|
|
from django.utils.html import format_html
|
|
|
|
from .models import (
|
|
Appreciation,
|
|
AppreciationAttachment,
|
|
AppreciationCategory,
|
|
AppreciationComment,
|
|
AppreciationReaction,
|
|
AppreciationStatus,
|
|
AppreciationType,
|
|
)
|
|
|
|
|
|
@admin.register(AppreciationCategory)
|
|
class AppreciationCategoryAdmin(admin.ModelAdmin):
|
|
"""Admin interface for AppreciationCategory"""
|
|
list_display = ['name', 'is_active', 'display_order', 'created_at']
|
|
list_filter = ['is_active']
|
|
search_fields = ['name', 'description']
|
|
list_editable = ['is_active', 'display_order']
|
|
|
|
|
|
class AppreciationReactionInline(admin.TabularInline):
|
|
"""Inline admin for AppreciationReaction"""
|
|
model = AppreciationReaction
|
|
extra = 0
|
|
readonly_fields = ['created_at']
|
|
|
|
|
|
class AppreciationCommentInline(admin.TabularInline):
|
|
"""Inline admin for AppreciationComment"""
|
|
model = AppreciationComment
|
|
extra = 0
|
|
readonly_fields = ['created_at', 'updated_at']
|
|
|
|
|
|
class AppreciationAttachmentInline(admin.TabularInline):
|
|
"""Inline admin for AppreciationAttachment"""
|
|
model = AppreciationAttachment
|
|
extra = 0
|
|
readonly_fields = ['filename', 'file_type', 'file_size', 'created_at']
|
|
|
|
|
|
@admin.register(Appreciation)
|
|
class AppreciationAdmin(admin.ModelAdmin):
|
|
"""Admin interface for Appreciation"""
|
|
list_display = [
|
|
'title',
|
|
'status_badge',
|
|
'type_badge',
|
|
'recipient_name',
|
|
'hospital',
|
|
'submitted_by',
|
|
'submitted_at',
|
|
]
|
|
list_filter = [
|
|
'status',
|
|
'appreciation_type',
|
|
'category',
|
|
'hospital',
|
|
'is_public',
|
|
'share_on_dashboard',
|
|
]
|
|
search_fields = ['title', 'description', 'recipient_name', 'story']
|
|
date_hierarchy = 'created_at'
|
|
readonly_fields = [
|
|
'created_at',
|
|
'updated_at',
|
|
'submitted_at',
|
|
'acknowledged_at',
|
|
'published_at',
|
|
]
|
|
|
|
fieldsets = (
|
|
('Basic Information', {
|
|
'fields': ('title', 'description', 'story')
|
|
}),
|
|
('Classification', {
|
|
'fields': ('appreciation_type', 'category', 'status')
|
|
}),
|
|
('Organization', {
|
|
'fields': ('hospital', 'department')
|
|
}),
|
|
('Recipient Information', {
|
|
'fields': ('recipient_name', 'recipient_type', 'recipient_id')
|
|
}),
|
|
('Submitter Information', {
|
|
'fields': ('submitted_by', 'submitter_role')
|
|
}),
|
|
('Acknowledgment', {
|
|
'fields': (
|
|
'acknowledged_by',
|
|
'acknowledged_at',
|
|
'acknowledgment_notes'
|
|
),
|
|
'classes': ('collapse',)
|
|
}),
|
|
('Timeline', {
|
|
'fields': ('submitted_at', 'published_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
('Visibility', {
|
|
'fields': ('is_public', 'share_on_dashboard', 'share_in_newsletter')
|
|
}),
|
|
('Additional Details', {
|
|
'fields': ('tags', 'impact_score', 'metadata'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
('System', {
|
|
'fields': ('created_at', 'updated_at', 'is_deleted'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
inlines = [
|
|
AppreciationAttachmentInline,
|
|
AppreciationReactionInline,
|
|
AppreciationCommentInline,
|
|
]
|
|
|
|
def status_badge(self, obj):
|
|
colors = {
|
|
'draft': 'gray',
|
|
'submitted': 'blue',
|
|
'acknowledged': 'orange',
|
|
'published': 'green',
|
|
'archived': 'gray',
|
|
}
|
|
color = colors.get(obj.status, 'gray')
|
|
return format_html(
|
|
'<span style="background-color: {}; color: white; padding: 3px 8px; border-radius: 3px;">{}</span>',
|
|
color,
|
|
obj.get_status_display()
|
|
)
|
|
status_badge.short_description = 'Status'
|
|
|
|
def type_badge(self, obj):
|
|
colors = {
|
|
'staff': 'blue',
|
|
'patient': 'green',
|
|
'department': 'orange',
|
|
'team': 'purple',
|
|
'individual': 'teal',
|
|
'group': 'pink',
|
|
}
|
|
color = colors.get(obj.appreciation_type, 'gray')
|
|
return format_html(
|
|
'<span style="background-color: {}; color: white; padding: 3px 8px; border-radius: 3px;">{}</span>',
|
|
color,
|
|
obj.get_appreciation_type_display()
|
|
)
|
|
type_badge.short_description = 'Type'
|
|
|
|
|
|
@admin.register(AppreciationAttachment)
|
|
class AppreciationAttachmentAdmin(admin.ModelAdmin):
|
|
"""Admin interface for AppreciationAttachment"""
|
|
list_display = [
|
|
'appreciation',
|
|
'filename',
|
|
'file_size',
|
|
'uploaded_by',
|
|
'created_at',
|
|
]
|
|
list_filter = ['appreciation__hospital', 'created_at']
|
|
search_fields = ['filename', 'appreciation__title', 'description']
|
|
readonly_fields = ['filename', 'file_type', 'file_size', 'created_at']
|
|
|
|
|
|
@admin.register(AppreciationReaction)
|
|
class AppreciationReactionAdmin(admin.ModelAdmin):
|
|
"""Admin interface for AppreciationReaction"""
|
|
list_display = [
|
|
'appreciation',
|
|
'user',
|
|
'reaction_type',
|
|
'created_at',
|
|
]
|
|
list_filter = ['reaction_type', 'created_at']
|
|
search_fields = ['user__email', 'appreciation__title']
|
|
readonly_fields = ['created_at']
|
|
|
|
|
|
@admin.register(AppreciationComment)
|
|
class AppreciationCommentAdmin(admin.ModelAdmin):
|
|
"""Admin interface for AppreciationComment"""
|
|
list_display = [
|
|
'appreciation',
|
|
'comment_short',
|
|
'user',
|
|
'is_internal',
|
|
'created_at',
|
|
]
|
|
list_filter = ['is_internal', 'created_at']
|
|
search_fields = ['comment', 'user__email', 'appreciation__title']
|
|
readonly_fields = ['created_at', 'updated_at']
|
|
|
|
def comment_short(self, obj):
|
|
return obj.comment[:50] + '...' if len(obj.comment) > 50 else obj.comment
|
|
comment_short.short_description = 'Comment' |