Add email config and check pending command task

This commit is contained in:
Gabriel Augendre 2020-08-18 22:26:46 +02:00
parent 9a610a482b
commit 6f4ec418ee
2 changed files with 30 additions and 0 deletions

View file

@ -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)

View file

@ -24,6 +24,20 @@ SECRET_KEY = os.getenv(
"SECRET_KEY", "s#!83!8e$3s89m)r$1ghsgxbndf8=#^qt(_*o%xbq0j2t8#db5" "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! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv("DEBUG", "true").lower() == "true" DEBUG = os.getenv("DEBUG", "true").lower() == "true"
TESTING = os.getenv("TESTING", "false").lower() == "true" TESTING = os.getenv("TESTING", "false").lower() == "true"