vault backup: 2025-12-26 02:09:22
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m29s
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m29s
This commit is contained in:
4
stroma/file/admin/__init__.py
Normal file
4
stroma/file/admin/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from .file_admin import FileAdmin
|
||||
|
||||
__all__ = ['FileAdmin']
|
||||
|
||||
88
stroma/file/admin/file_admin.py
Normal file
88
stroma/file/admin/file_admin.py
Normal file
@@ -0,0 +1,88 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
from file.models import File
|
||||
|
||||
|
||||
@admin.register(File)
|
||||
class FileAdmin(admin.ModelAdmin):
|
||||
"""Admin interface for Files"""
|
||||
list_display = ['id', 'name_with_icon', 'path_display', 'mime_type_display', 'parent_display', 'children_count', 'created_at']
|
||||
list_filter = ['mime_type', 'created_at', 'user']
|
||||
search_fields = ['name', 'path', 'mime_type', 'text']
|
||||
readonly_fields = ['created_at', 'updated_at', 'text_preview']
|
||||
fieldsets = [
|
||||
('File Info', {
|
||||
'fields': ['name', 'path', 'mime_type', 'parent', 'user']
|
||||
}),
|
||||
('Content', {
|
||||
'fields': ['text_preview', 'external_url'],
|
||||
'classes': ['collapse']
|
||||
}),
|
||||
('Metadata', {
|
||||
'fields': ['metadata'],
|
||||
'classes': ['collapse']
|
||||
}),
|
||||
('Timestamps', {
|
||||
'fields': ['created_at', 'updated_at'],
|
||||
'classes': ['collapse']
|
||||
}),
|
||||
]
|
||||
|
||||
def name_with_icon(self, obj):
|
||||
"""Show name with icon based on mime type"""
|
||||
icon = '📁' if obj.mime_type == 'application/x-folder' else '📄'
|
||||
if obj.mime_type.startswith('text/markdown'):
|
||||
icon = '📝'
|
||||
elif obj.mime_type.startswith('application/pdf'):
|
||||
icon = '📕'
|
||||
elif obj.mime_type.startswith('video/'):
|
||||
icon = '🎥'
|
||||
return format_html('{} <strong>{}</strong>', icon, obj.name)
|
||||
name_with_icon.short_description = 'Name'
|
||||
|
||||
def path_display(self, obj):
|
||||
"""Show path with folder/file distinction"""
|
||||
if obj.path:
|
||||
parts = obj.path.split('/')
|
||||
if len(parts) > 1:
|
||||
folder_path = '/'.join(parts[:-1])
|
||||
return format_html('<span style="color: #666;">{}/</span>{}', folder_path, parts[-1])
|
||||
return obj.path or '-'
|
||||
path_display.short_description = 'Path'
|
||||
|
||||
def mime_type_display(self, obj):
|
||||
"""Show mime type with color coding"""
|
||||
color = '#999'
|
||||
if obj.mime_type == 'application/x-folder':
|
||||
color = '#3b82f6'
|
||||
elif obj.mime_type.startswith('text/'):
|
||||
color = '#10b981'
|
||||
elif obj.mime_type.startswith('application/pdf'):
|
||||
color = '#ef4444'
|
||||
return format_html('<span style="color: {};">{}</span>', color, obj.mime_type)
|
||||
mime_type_display.short_description = 'MIME Type'
|
||||
|
||||
def parent_display(self, obj):
|
||||
"""Show parent file"""
|
||||
if obj.parent:
|
||||
icon = '📁' if obj.parent.mime_type == 'application/x-folder' else '📄'
|
||||
return format_html('{} {}', icon, obj.parent.name)
|
||||
return '-'
|
||||
parent_display.short_description = 'Parent'
|
||||
|
||||
def children_count(self, obj):
|
||||
"""Show number of child files"""
|
||||
count = obj.children.count()
|
||||
if count > 0:
|
||||
return format_html('<span style="color: #3b82f6; font-weight: bold;">{}</span>', count)
|
||||
return '-'
|
||||
children_count.short_description = '# Children'
|
||||
|
||||
def text_preview(self, obj):
|
||||
"""Show text content preview"""
|
||||
if obj.text:
|
||||
preview = obj.text[:200] + '...' if len(obj.text) > 200 else obj.text
|
||||
return format_html('<pre style="white-space: pre-wrap;">{}</pre>', preview)
|
||||
return '-'
|
||||
text_preview.short_description = 'Text Content'
|
||||
|
||||
Reference in New Issue
Block a user