mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 16:11:08 -05:00
- Implemented PrimeProgress component with support for labels, helper text, and various styles (size, variant, color). - Created PrimeSelect component with dropdown functionality, custom templates, and validation states. - Developed PrimeSkeleton component for loading placeholders with different shapes and animations. - Updated index.ts to export new components for easy import. - Enhanced PrimeVueTest.vue to include tests for new components and their functionalities. - Introduced a custom ThrillWiki theme for PrimeVue with tailored color schemes and component styles. - Added ambient type declarations for various components to improve TypeScript support.
107 lines
3.1 KiB
Python
107 lines
3.1 KiB
Python
"""
|
|
Centralized email service API views.
|
|
Migrated from apps.email_service.views
|
|
"""
|
|
|
|
from rest_framework.views import APIView
|
|
from rest_framework.response import Response
|
|
from rest_framework import status
|
|
from rest_framework.permissions import AllowAny
|
|
from django.contrib.sites.shortcuts import get_current_site
|
|
from drf_spectacular.utils import extend_schema
|
|
from apps.email_service.services import EmailService
|
|
|
|
|
|
@extend_schema(
|
|
summary="Send email",
|
|
description="Send an email via the email service.",
|
|
request={
|
|
"type": "object",
|
|
"properties": {
|
|
"to": {
|
|
"type": "string",
|
|
"format": "email",
|
|
"description": "Recipient email address",
|
|
},
|
|
"subject": {"type": "string", "description": "Email subject"},
|
|
"text": {"type": "string", "description": "Email body text"},
|
|
"from_email": {
|
|
"type": "string",
|
|
"format": "email",
|
|
"description": "Sender email address (optional)",
|
|
},
|
|
},
|
|
"required": ["to", "subject", "text"],
|
|
},
|
|
responses={
|
|
200: {
|
|
"type": "object",
|
|
"properties": {
|
|
"message": {"type": "string"},
|
|
"response": {"type": "object"},
|
|
},
|
|
},
|
|
400: "Bad Request",
|
|
500: "Internal Server Error",
|
|
},
|
|
tags=["Email"],
|
|
)
|
|
class SendEmailView(APIView):
|
|
"""
|
|
API endpoint for sending emails.
|
|
|
|
Migrated from apps.email_service.views.SendEmailView to centralized API structure.
|
|
"""
|
|
|
|
permission_classes = [AllowAny] # Allow unauthenticated access
|
|
|
|
def post(self, request):
|
|
"""
|
|
Send an email via the email service.
|
|
|
|
Request body:
|
|
{
|
|
"to": "recipient@example.com",
|
|
"subject": "Email subject",
|
|
"text": "Email body text",
|
|
"from_email": "sender@example.com" // optional
|
|
}
|
|
"""
|
|
data = request.data
|
|
to = data.get("to")
|
|
subject = data.get("subject")
|
|
text = data.get("text")
|
|
from_email = data.get("from_email") # Optional
|
|
|
|
if not all([to, subject, text]):
|
|
return Response(
|
|
{
|
|
"error": "Missing required fields",
|
|
"required_fields": ["to", "subject", "text"],
|
|
},
|
|
status=status.HTTP_400_BAD_REQUEST,
|
|
)
|
|
|
|
try:
|
|
# Get the current site
|
|
site = get_current_site(request)
|
|
|
|
# Send email using the site's configuration
|
|
response = EmailService.send_email(
|
|
to=to,
|
|
subject=subject,
|
|
text=text,
|
|
from_email=from_email, # Will use site's default if None
|
|
site=site,
|
|
)
|
|
|
|
return Response(
|
|
{"message": "Email sent successfully", "response": response},
|
|
status=status.HTTP_200_OK,
|
|
)
|
|
|
|
except Exception as e:
|
|
return Response(
|
|
{"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
|
)
|