from django.contrib.auth.decorators import login_required from django.shortcuts import render from django.utils import timezone from django.utils.decorators import method_decorator from django.views.generic import TemplateView from oauth2_provider.contrib.rest_framework import IsAuthenticatedOrTokenHasScope from rest_framework import generics from rest_framework.exceptions import APIException, ErrorDetail from rest_framework.permissions import AllowAny from rest_framework.response import Response from rest_framework.views import APIView from utils.exceptions import StatusError # Create your views here. @method_decorator(login_required, name='dispatch') class HomeView(TemplateView): template_name = 'core/home.html' class StatusView(APIView): permission_classes = [AllowAny] def get(self, request, format=None): if self.request.GET.get('raise_error'): raise StatusError( # code='service_unavailable_at_now', detail={ # "code": 'service_unavailable_at_now', "timestamp": timezone.now().isoformat(), "message": "برخی سرویس‌های خارجی در دسترس نیستند لطفا بعدا تلاش کنید" }, ) data = { "status": "ok", } return Response(data) class HealthcheckView(APIView): permission_classes = [AllowAny] def get(self, request, format=None): data = { "is_healthy": True } return Response(data)