94 lines
2.8 KiB
Python
94 lines
2.8 KiB
Python
from django.contrib import admin
|
|
from django.utils.html import format_html
|
|
|
|
from .models import Filament, Submission
|
|
|
|
|
|
@admin.register(Filament)
|
|
class FilamentAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"display_label",
|
|
"material",
|
|
"color_name",
|
|
"swatch",
|
|
"is_available",
|
|
"sort_order",
|
|
"notes",
|
|
)
|
|
list_editable = ("is_available", "sort_order", "notes")
|
|
list_filter = ("material", "is_available")
|
|
search_fields = ("color_name", "material", "notes")
|
|
readonly_fields = ("id", "created_at", "updated_at")
|
|
ordering = ("sort_order", "color_name")
|
|
|
|
@admin.display(description="Swatch")
|
|
def swatch(self, obj: Filament) -> str:
|
|
if not obj.swatch_hex:
|
|
return "—"
|
|
return format_html(
|
|
'<span title="{0}" style="display:inline-block;width:1.25rem;height:1.25rem;border-radius:0.25rem;border:1px solid #cbd5e1;background:{0};"></span>',
|
|
obj.swatch_hex,
|
|
)
|
|
|
|
|
|
@admin.register(Submission)
|
|
class SubmissionAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"slug",
|
|
"status",
|
|
"submitter_display",
|
|
"source_type",
|
|
"requested_filament",
|
|
"created_at",
|
|
"closed_by",
|
|
)
|
|
list_filter = ("status", "source_type", "requested_filament")
|
|
search_fields = (
|
|
"slug",
|
|
"guest_email",
|
|
"submitted_by__username",
|
|
"submitted_by__email",
|
|
)
|
|
date_hierarchy = "created_at"
|
|
ordering = ("-created_at",)
|
|
autocomplete_fields = ("requested_filament",)
|
|
readonly_fields = (
|
|
"id",
|
|
"slug",
|
|
"confirmation_token",
|
|
"confirmation_sent_at",
|
|
"email_confirmed",
|
|
"created_at",
|
|
"updated_at",
|
|
"closed_at",
|
|
)
|
|
fieldsets = (
|
|
("Identity", {
|
|
"fields": ("slug", "id", "submitted_by", "guest_email"),
|
|
}),
|
|
("Source", {
|
|
"fields": ("source_type", "stl_file", "source_url", "requested_filament"),
|
|
}),
|
|
("User-provided", {
|
|
"fields": ("notes_for_op",),
|
|
"description": "Private notes from the submitter -- never shown publicly.",
|
|
}),
|
|
("Status & operator", {
|
|
"fields": ("status", "operator_notes", "closed_by", "closed_at"),
|
|
}),
|
|
("Confirmation (guest path)", {
|
|
"fields": ("email_confirmed", "confirmation_token", "confirmation_sent_at"),
|
|
"classes": ("collapse",),
|
|
}),
|
|
("Timestamps", {
|
|
"fields": ("created_at", "updated_at"),
|
|
"classes": ("collapse",),
|
|
}),
|
|
)
|
|
|
|
@admin.display(description="Submitter", ordering="submitted_by")
|
|
def submitter_display(self, obj: Submission) -> str:
|
|
if obj.submitted_by_id:
|
|
return str(obj.submitted_by)
|
|
return f"guest <{obj.guest_email}>" if obj.guest_email else "guest"
|