Files
interchan/board/admin.py
Alek Ratzloff 6bda7f4f2d Big upheaval of how the reports system works
* There are now Reports and ReportRecords.
* Reports coordinate to what moderators see, and ReportRecords
  coordinate with the reports that are created by individual users.
* Reports keep track of the report reason and the creating user.
* ReportRecords keep track of the total weight and whether this report
  requires urgent attention or not.
* ReportRecord keeps track of its own weight and urgency because then we
  can sort by weight and urgency in the admin view.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-06-19 22:03:01 -07:00

48 lines
1.1 KiB
Python

from django.contrib import admin
from django.utils.safestring import mark_safe
from board.models import Board, Post, ReportReason, ReportRecord
@admin.register(Board)
class BoardAdmin(admin.ModelAdmin):
pass
@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
pass
@admin.register(ReportReason)
class ReportReasonAdmin(admin.ModelAdmin):
pass
@admin.register(ReportRecord)
class ReportRecordAdmin(admin.ModelAdmin):
ordering = (
"-urgent",
"-weight",
)
readonly_fields = ("post",)
list_display = ("post_thumbnail", "post_body")
save_as = False
def post_thumbnail(self, obj):
if obj.post.thumbnail:
return mark_safe(f'<img src="{obj.post.thumbnail.url}" />')
else:
return None
def post_body(self, obj):
html = ""
if obj.urgent:
html += '<div class="urgent">'
else:
html += "<div>"
if obj.post.subject:
html += f"<strong>{obj.post.subject}</strong>"
html += f"<p>{obj.post.text}</p>"
html += "</div>"
return mark_safe(html)