37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from django.contrib.auth.models import User
|
|
from django.http import JsonResponse
|
|
from rest_framework import status
|
|
from rest_framework.permissions import IsAuthenticated
|
|
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.filter(email=email)
|
|
|
|
if user:
|
|
subscribe_for_user = SubscribeForUser.objects.filter(user_id=user[0].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 JsonResponse({"message": "Subscriptions updated successfully"}, status=status.HTTP_200_OK)
|
|
|
|
return JsonResponse({"message": "User not found"}, status=status.HTTP_404_NOT_FOUND)
|