Add weekly new products email and related features
Introduces a weekly summary email for newly added products, including a new email template and Celery periodic task. Adds 'include_in_week_summary_email' to Product and 'newsletter' to CustomUser. Provides an admin endpoint to manually trigger the weekly email, updates Celery Beat schedule, and adds email templates for verification and password reset.
This commit is contained in:
@@ -3,11 +3,12 @@ from rest_framework.response import Response
|
||||
from rest_framework import status, viewsets
|
||||
from rest_framework.permissions import AllowAny, IsAdminUser
|
||||
from rest_framework.authentication import SessionAuthentication
|
||||
from rest_framework.decorators import api_view, permission_classes
|
||||
from drf_spectacular.utils import extend_schema, extend_schema_view
|
||||
|
||||
from .models import ContactMe
|
||||
from .serializer import ContactMeSerializer
|
||||
from .tasks import send_contact_me_email_task
|
||||
from .tasks import send_contact_me_email_task, send_newly_added_items_to_store_email_task_last_week
|
||||
|
||||
|
||||
@extend_schema(tags=["advertisement", "public"])
|
||||
@@ -54,3 +55,32 @@ class ContactMeAdminViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = ContactMeSerializer
|
||||
permission_classes = [IsAdminUser]
|
||||
|
||||
|
||||
@extend_schema(
|
||||
tags=["advertisement"],
|
||||
summary="Manually trigger weekly new items email",
|
||||
description="Triggers the weekly email task that sends a summary of newly added products from the last week. Only accessible by admin users.",
|
||||
methods=["POST"]
|
||||
)
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAdminUser])
|
||||
def trigger_weekly_email(request):
|
||||
"""
|
||||
Manually trigger the weekly new items email task.
|
||||
Only accessible by admin users.
|
||||
"""
|
||||
try:
|
||||
# Trigger the task asynchronously
|
||||
task = send_newly_added_items_to_store_email_task_last_week.delay()
|
||||
|
||||
return Response({
|
||||
'success': True,
|
||||
'message': 'Weekly email task triggered successfully',
|
||||
'task_id': task.id
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
except Exception as e:
|
||||
return Response({
|
||||
'success': False,
|
||||
'message': f'Failed to trigger weekly email task: {str(e)}'
|
||||
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
Reference in New Issue
Block a user