"""
API file for news and event app

consists of the news list, detail and add api
events list, detail and add api
"""

from django.utils import timezone

from rest_framework import status, mixins
from rest_framework.authentication import TokenAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import detail_route, list_route
from rest_framework.response import Response
from rest_framework import viewsets

from news_event.models import News, Event
from news_event.serializers import NewsSerializer, EventSerializer 


class NewsViewSet(mixins.ListModelMixin,
                mixins.RetrieveModelMixin,
                mixins.CreateModelMixin,
                viewsets.GenericViewSet):
    
    queryset = News.objects.all()
    serializer_class = NewsSerializer
    

class EventViewSet(mixins.ListModelMixin,
                mixins.RetrieveModelMixin,
                mixins.CreateModelMixin,
                viewsets.GenericViewSet):
    
    queryset = Event.objects.approved()
    serializer_class = EventSerializer
    
    


@@ -584,16 +584,49 @@
 lizer %0A%0A
+from UCP.constants import result%0A
 %0Aclass N
@@ -1125,14 +1125,871 @@
 er%0A    %0A    
-%0A
+@detail_route(methods=%5B'post'%5D)%0A    def approve(self, request, pk):%0A        response = %7B%7D%0A%0A        if Event.objects.pending().filter(id = pk).exists():%0A            event = Event.objects.get(id = pk)%0A            event.is_approved = True%0A            event.save()%0A%0A            response%5B%22result%22%5D = result.RESULT_SUCCESS%0A        else:%0A            response%5B%22result%22%5D = result.RESULT_FAILURE%0A            response%5B%22error%22%5D = %22This Event id does not exist%22%0A            %0A    %0A        return Response(response, status=status.HTTP_200_OK)%0A    %0A    %0A    def get_queryset(self):%0A        if self.action == %22approve%22:%0A            return Event.objects.all()%0A        else:%0A            return Event.objects.approved()%0A            %0A    def get_serializer_class(self):%0A        if self.action == %22approve%22:%0A            return None%0A        else:%0A            return EventSerializer
 %0A

Add event approval api