Source code for nkdsu.apps.vote.views.api
import json
from abc import ABC, abstractmethod
from typing import TypeVar
from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpRequest, HttpResponse
from django.views.generic import View
from django.views.generic.detail import SingleObjectMixin
from ..api_utils import JsonDict, JsonEncodable, JsonList, Serializable
from ..mixins import ShowDetailMixin, ThisShowDetailMixin, TwitterUserDetailMixin
from ..models import Track
from ..views import Search
S = TypeVar("S", bound=Serializable)
[docs]
class APIView(View, ABC):
[docs]
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
resp = HttpResponse(
json.dumps(self.get_api_stuff(), cls=DjangoJSONEncoder, indent=2),
content_type='application/json',
)
resp['Access-Control-Allow-Origin'] = '*'
return resp