добавить возможность для отправки на почту
This commit is contained in:
parent
527dd8a20f
commit
27253c2ed2
|
|
@ -0,0 +1,32 @@
|
||||||
|
from rest_framework.schemas import AutoSchema
|
||||||
|
import coreapi
|
||||||
|
import coreschema
|
||||||
|
|
||||||
|
class SendMailSchema(AutoSchema):
|
||||||
|
def get_serializer_fields(self, path, method):
|
||||||
|
return [
|
||||||
|
coreapi.Field(
|
||||||
|
name='FCs',
|
||||||
|
location='form',
|
||||||
|
required=False,
|
||||||
|
schema=coreschema.String(description='ФИО')
|
||||||
|
),
|
||||||
|
coreapi.Field(
|
||||||
|
name='Name of organization',
|
||||||
|
location='form',
|
||||||
|
required=False,
|
||||||
|
schema=coreschema.String(description='Название организации')
|
||||||
|
),
|
||||||
|
coreapi.Field(
|
||||||
|
name='Email',
|
||||||
|
location='form',
|
||||||
|
required=False,
|
||||||
|
schema=coreschema.String(description='Почта отправителя')
|
||||||
|
),
|
||||||
|
coreapi.Field(
|
||||||
|
name='Text',
|
||||||
|
location='form',
|
||||||
|
required=False,
|
||||||
|
schema=coreschema.String(description='Текст сообщения')
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
from rest_framework.viewsets import GenericViewSet
|
from rest_framework.viewsets import GenericViewSet
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from .models import Team, SupportInfo
|
from rest_framework.decorators import action
|
||||||
from .serializers import TeamSerializer, SupportInfoSerializer
|
from config_site.models import Team, SupportInfo
|
||||||
|
from config_site.schemas import SendMailSchema
|
||||||
|
from config_site.serializers import TeamSerializer, SupportInfoSerializer
|
||||||
|
from django.core.mail import EmailMessage
|
||||||
|
from conf import settings
|
||||||
|
|
||||||
|
|
||||||
class TeamViewSet(GenericViewSet):
|
class TeamViewSet(GenericViewSet):
|
||||||
|
|
@ -22,4 +26,16 @@ class SupportInfoViewSet(GenericViewSet):
|
||||||
queryset = self.get_queryset().first()
|
queryset = self.get_queryset().first()
|
||||||
serializer = self.get_serializer(queryset)
|
serializer = self.get_serializer(queryset)
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
@action(detail=False, methods=['post'], schema=SendMailSchema())
|
||||||
|
def send_mail(self, request):
|
||||||
|
title = f"{request.data.get('Name of organization')} - {request.data.get('FCs')}"
|
||||||
|
email = EmailMessage(
|
||||||
|
title,
|
||||||
|
request.data.get('Text'),
|
||||||
|
settings.EMAIL_HOST_USER,
|
||||||
|
(request.data.get('Email'),)
|
||||||
|
)
|
||||||
|
email.send()
|
||||||
|
return Response("Сообщение успешно отправлено!", status=status.HTTP_200_OK)
|
||||||
|
|
||||||
Loading…
Reference in New Issue