diff --git a/articles/management/commands/check_pending_comments.py b/articles/management/commands/check_pending_comments.py new file mode 100644 index 0000000..1431be8 --- /dev/null +++ b/articles/management/commands/check_pending_comments.py @@ -0,0 +1,16 @@ +from django.core.mail import mail_admins +from django.core.management import BaseCommand + +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): + count = Comment.objects.filter(status=Comment.PENDING) + # url = reverse("admin:articles_comment_list") + url = "" + if count: + message = f"There are {count} comments pending[0].\n[0]: {url}" + mail_admins("Comments pending", message) diff --git a/blog/settings.py b/blog/settings.py index 06725ba..9313774 100644 --- a/blog/settings.py +++ b/blog/settings.py @@ -24,6 +24,20 @@ SECRET_KEY = os.getenv( "SECRET_KEY", "s#!83!8e$3s89m)r$1ghsgxbndf8=#^qt(_*o%xbq0j2t8#db5" ) +admins = os.getenv("ADMINS", "") +if admins: + ADMINS = list(map(lambda x: tuple(x.split(",")), admins.split(";"))) + +DEFAULT_FROM_EMAIL = "blog@gabnotes.org" +SERVER_EMAIL = "blog@gabnotes.org" +EMAIL_HOST = os.getenv("EMAIL_HOST", "localhost") +EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "") +EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "") +EMAIL_PORT = 465 +EMAIL_SUBJECT_PREFIX = "[Blog] " +EMAIL_USE_TLS = True +EMAIL_TIMEOUT = 30 + # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.getenv("DEBUG", "true").lower() == "true" TESTING = os.getenv("TESTING", "false").lower() == "true"