Add ability to create bans from reports
This is done in the admin view and opens a new iframed window. The ban form is pretty barebones and doesn't have full functionality yet, but that is coming. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
from django import forms
|
||||
from django.contrib import admin
|
||||
from django.http.response import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from django.utils.safestring import mark_safe
|
||||
from board.models import Ban, Board, Post, RangeBan, ReportReason, ReportRecord
|
||||
|
||||
|
||||
#
|
||||
# Admin sites
|
||||
#
|
||||
@admin.register(Board)
|
||||
class BoardAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
@@ -18,16 +24,23 @@ class ReportReasonAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
class BanFromReportForm(forms.ModelForm):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(ReportRecord)
|
||||
class ReportRecordAdmin(admin.ModelAdmin):
|
||||
ordering = (
|
||||
"-urgent",
|
||||
"-weight",
|
||||
)
|
||||
readonly_fields = ("post",)
|
||||
list_display = ("post_thumbnail", "post_body")
|
||||
readonly_fields = ("post", "weight", "urgent")
|
||||
list_display = ("post_id", "post_thumbnail", "post_body", "create_ban")
|
||||
save_as = False
|
||||
|
||||
def post_id(self, obj):
|
||||
return obj.post.id
|
||||
|
||||
def post_thumbnail(self, obj):
|
||||
if obj.post.thumbnail:
|
||||
return mark_safe(f'<img src="{obj.post.thumbnail.url}" />')
|
||||
@@ -41,11 +54,19 @@ class ReportRecordAdmin(admin.ModelAdmin):
|
||||
else:
|
||||
html += "<div>"
|
||||
if obj.post.subject:
|
||||
html += f"<strong>{obj.post.subject}</strong>"
|
||||
html += f"<p><strong>{obj.post.subject}</strong></p>"
|
||||
html += f"<p>{obj.post.text}</p>"
|
||||
html += "</div>"
|
||||
return mark_safe(html)
|
||||
|
||||
def create_ban(self, obj):
|
||||
post = obj.post
|
||||
board = obj.post.board
|
||||
ban_url = reverse("board:ban_create", kwargs={"url": board.url, "id": post.id})
|
||||
return mark_safe(
|
||||
f'<a href="#" data-ban-url="{ban_url}" class="ban_link">Ban</a>'
|
||||
)
|
||||
|
||||
|
||||
@admin.register(RangeBan)
|
||||
class RangeBanAdmin(admin.ModelAdmin):
|
||||
|
||||
Reference in New Issue
Block a user