10 changed files with 161 additions and 0 deletions
@ -0,0 +1,15 @@
|
||||
|
||||
from django.contrib.auth import get_user_model |
||||
from django.contrib.sites.shortcuts import get_current_site |
||||
from django.db.models import Sum |
||||
from django.db.models.signals import post_save, pre_save |
||||
from django.dispatch import receiver |
||||
|
||||
from .models import Album |
||||
from .tasks import send_new_album_notification |
||||
|
||||
|
||||
@receiver(post_save, sender=Album) |
||||
def post_save_album_instance(sender, instance, created, **kwargs): |
||||
if created: |
||||
send_new_album_notification.delay(instance.id) |
@ -0,0 +1,36 @@
|
||||
import datetime |
||||
from itertools import chain |
||||
|
||||
import numpy as np |
||||
from celery import shared_task |
||||
from celery.utils.log import get_task_logger |
||||
from django.conf import settings |
||||
from django.contrib.auth import get_user_model |
||||
from django.core import mail |
||||
from django.core.mail import EmailMultiAlternatives |
||||
from django.core.mail.backends.smtp import EmailBackend |
||||
from django.db.models.expressions import F |
||||
from django.template.loader import render_to_string |
||||
from django.utils.html import strip_tags |
||||
from django.utils.timezone import make_aware |
||||
|
||||
from .models import Album |
||||
|
||||
|
||||
@shared_task(name='send_new_album_notification') |
||||
def send_new_album_notification(album_id): |
||||
|
||||
album = Album.objects.get(id=album_id) |
||||
subject = 'New Image added | Verification Required - ungleich' |
||||
context = { |
||||
'subject': subject, |
||||
'album': album |
||||
} |
||||
html_message = render_to_string('email/new_album_notification.html', context) |
||||
plain_message = strip_tags(html_message) |
||||
from_email = settings.EMAIL_HOST_USER |
||||
print(from_email) |
||||
|
||||
se_mail = mail.send_mail( |
||||
subject, plain_message, from_email, [from_email], html_message=html_message |
||||
) |
@ -0,0 +1,4 @@
|
||||
|
||||
from __future__ import absolute_import |
||||
|
||||
from .celery import app as celery_app |
@ -0,0 +1,32 @@
|
||||
|
||||
from __future__ import absolute_import, unicode_literals |
||||
|
||||
import os |
||||
|
||||
from celery import Celery |
||||
from django.conf import settings |
||||
|
||||
from . import celeryconfig |
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.development') |
||||
|
||||
app = Celery('config', |
||||
broker=celeryconfig.broker_url, |
||||
backend=celeryconfig.result_backend) |
||||
|
||||
app.config_from_object("config.celeryconfig") |
||||
app.autodiscover_tasks(settings.INSTALLED_APPS) |
||||
|
||||
|
||||
@app.task(bind=True) |
||||
def debug_task(self): |
||||
print('Request: {0!r}'.format(self.request)) |
||||
|
||||
from celery.schedules import crontab |
||||
|
||||
app.conf.beat_schedule = { |
||||
# 'scan_images_to_convert_into_webp_format': { |
||||
# 'task': 'products.tasks.scan_images_to_convert_into_webp_format', |
||||
# 'schedule': crontab(minute='*/5'), # Executes every 5 minutes |
||||
# }, |
||||
} |
@ -0,0 +1,7 @@
|
||||
import os |
||||
import tempfile |
||||
|
||||
broker_url = "redis://localhost:6379/0" |
||||
result_backend = "redis://localhost:6379/0" |
||||
accept_content = ["pickle", "json", "msgpack", "yaml"] |
||||
task_ignore_result = False |
Binary file not shown.
@ -0,0 +1,24 @@
|
||||
{% load static %} |
||||
|
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
|
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<meta http-equiv="x-ua-compatible" content="ie=edge"> |
||||
<title>{{ subject }}</title> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
<meta name="description" content=""> |
||||
<meta name="author" content="ungleich"> |
||||
<link rel="icon" href="{% static 'images/favicons/favicon.ico' %}"> |
||||
|
||||
</head> |
||||
|
||||
<body> |
||||
|
||||
<div class="container"> |
||||
<p>Hi there, there have a new image request added, which needs verification. Please follow the <a href="http://127.0.0.1:8000/admin/album/album/{{album.id}}/change/">link</a> to verify</p> |
||||
</div> |
||||
</body> |
||||
|
||||
</html> |
Loading…
Reference in new issue