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

29 lines
1 KiB
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
2020-08-20 10:12:33 +02:00
from django.utils.translation import ngettext
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"
2020-09-05 09:09:59 +02:00
message = (
ngettext(
"There is %(count)d comment pending review.\n%(url)s",
"There are %(count)d comments pending review.\n%(url)s",
count,
)
% {"count": count, "url": url}
)
2020-08-20 10:12:33 +02:00
mail_admins("Comments pending review", message)