A9: operations console, three pause commands, admin and player reports (WEB-30..32, WEB-40..44, WEB-55, AUD-48)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3d1e820564
commit
eab141f467
24 files changed
+928
-11
No files matched your search
@@ -0,0 +1,77 @@
|
||||
"""Admin for the lottery tables (WEB-32): closed rounds, transactions, movements and the audit are read-only;
|
||||
reports are managed by changing their status, which is audited."""
|
||||
|
||||
from django.contrib import admin
|
||||
from django.db import transaction
|
||||
|
||||
from . import audit
|
||||
from .models import AuditEntry, ChainTransaction, Movement, Participation, Report, Round
|
||||
|
||||
|
||||
class ReadOnlyAdmin(admin.ModelAdmin):
|
||||
def has_add_permission(self, request):
|
||||
return False
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
|
||||
@admin.register(Round)
|
||||
class RoundAdmin(ReadOnlyAdmin):
|
||||
list_display = ("id", "status", "opened_at", "closed_at", "pool_amount_sats")
|
||||
list_filter = ("status",)
|
||||
|
||||
|
||||
@admin.register(Participation)
|
||||
class ParticipationAdmin(ReadOnlyAdmin):
|
||||
list_display = ("id", "round", "user", "status", "bet_amount_sats")
|
||||
list_filter = ("status",)
|
||||
|
||||
|
||||
@admin.register(Movement)
|
||||
class MovementAdmin(ReadOnlyAdmin):
|
||||
list_display = ("id", "user", "kind", "status", "amount_sats", "created_at")
|
||||
list_filter = ("kind", "status")
|
||||
|
||||
|
||||
@admin.register(ChainTransaction)
|
||||
class ChainTransactionAdmin(ReadOnlyAdmin):
|
||||
list_display = ("id", "kind", "status", "current_txid", "created_at")
|
||||
list_filter = ("kind", "status")
|
||||
exclude = ("raw_hex",)
|
||||
|
||||
|
||||
@admin.register(AuditEntry)
|
||||
class AuditEntryAdmin(ReadOnlyAdmin):
|
||||
list_display = ("created_at", "actor_label", "action", "outcome", "subject_type", "subject_id")
|
||||
list_filter = ("action", "outcome")
|
||||
search_fields = ("actor_label", "reason")
|
||||
|
||||
|
||||
@admin.register(Report)
|
||||
class ReportAdmin(admin.ModelAdmin):
|
||||
list_display = ("id", "user", "status", "created_at")
|
||||
list_filter = ("status",)
|
||||
fields = ("user", "text", "created_at", "status", "status_changed_at")
|
||||
readonly_fields = ("user", "text", "created_at", "status_changed_at")
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
if not (change and "status" in form.changed_data):
|
||||
return
|
||||
from django.utils import timezone
|
||||
|
||||
before = form.initial.get("status")
|
||||
with transaction.atomic():
|
||||
obj.status_changed_at = timezone.now()
|
||||
obj.save(update_fields=["status", "status_changed_at"])
|
||||
audit.record("report_status_changed", actor=request.user, subject_type="report", subject_id=obj.pk,
|
||||
payload={"from": before, "to": obj.status})
|
||||
Reference in new issue
Block a user