This repository has been archived on 2023-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
python-blog/articles/management/commands/check_pending_comments.py

21 lines
741 B
Python
Raw Normal View History

2020-08-19 12:13:44 +02:00
from django.conf import settings
from django.core.mail import mail_admins
from django.core.management import BaseCommand
2020-08-19 12:13:44 +02:00
from django.urls import reverse
from articles.models import Comment
class Command(BaseCommand):
help = "Check for pending comments and send an email to the admin."
def handle(self, *args, **options):
2020-08-19 12:13:44 +02:00
count = Comment.objects.filter(status=Comment.PENDING).count()
if count:
2020-08-19 12:13:44 +02:00
url = reverse("admin:articles_comment_changelist")
url = (settings.BLOG["base_url"] + url).replace(
"//", "/"
) + "?status__exact=pending"
message = f"There are {count} comments pending review.\n{url}"
mail_admins("Comments pending", message)