Files

31 lines
1.1 KiB
Python

from django.contrib import admin
from django_object_actions import DjangoObjectActions, action
from .canvas import rebuild_canvas_from_history
from .models import PixelPlacement, PlaceSettings
@admin.register(PlaceSettings)
class PlaceSettingsAdmin(DjangoObjectActions, admin.ModelAdmin):
list_display = ("event", "width", "height", "placement_ends_at")
list_editable = ("width", "height", "placement_ends_at")
list_filter = ("event",)
change_actions = ("resync_canvas",)
@action(
label="Resync canvas from DB",
description="Rebuild the live Redis canvas by replaying the full PixelPlacement history",
)
def resync_canvas(self, request, obj):
count = rebuild_canvas_from_history(obj.event, obj.width, obj.height)
self.message_user(
request,
f"Canvas resynced from {count} placement(s) at {obj.width}x{obj.height}.",
)
@admin.register(PixelPlacement)
class PixelPlacementAdmin(admin.ModelAdmin):
list_display = ("id", "event", "player", "x", "y", "color_index", "placed_at")
list_filter = ("event", "player")