33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from django.contrib.auth.models import User
|
|
from rest_framework import status
|
|
from rest_framework.permissions import IsAuthenticated
|
|
from rest_framework.response import Response
|
|
from rest_framework.views import APIView
|
|
|
|
from SubscribesApp.models import SubscribeForUser
|
|
|
|
|
|
class SubscribersView(APIView):
|
|
# permission_classes = [IsAuthenticated]
|
|
|
|
def post(self, request):
|
|
data = request.data
|
|
email = data['email']
|
|
email_notification = data['email_notification']
|
|
auto_subscribe = data['auto_subscribe']
|
|
|
|
user = User.objects.get(email=email)
|
|
subscribe_for_user = SubscribeForUser.objects.filter(user_id=user.id)
|
|
|
|
if email_notification:
|
|
subscribe_for_user.update(receive_finish_subscribe_msg=True)
|
|
else:
|
|
subscribe_for_user.update(receive_finish_subscribe_msg=False)
|
|
|
|
if auto_subscribe:
|
|
subscribe_for_user.update(auto_continue=True)
|
|
else:
|
|
subscribe_for_user.update(auto_continue=False)
|
|
|
|
return Response("Subscriptions updated successfully", status=status.HTTP_200_OK)
|