48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
from django.contrib.auth.decorators import login_required
|
|
from django.shortcuts import render
|
|
from django.utils.decorators import method_decorator
|
|
from django.views.generic import ListView, DetailView
|
|
from rest_framework import generics
|
|
|
|
from .models import App
|
|
from .serializers import AppSerializer
|
|
from ..gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
class AppListView(ListView):
|
|
model = App
|
|
template_name = 'superapp/app_list.html'\
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
class AppDetailView(DetailView):
|
|
model = App
|
|
template_name = 'superapp/app_detail.html'
|
|
pk_url_kwarg = 'uuid'
|
|
|
|
# def get_queryset(self):
|
|
# return App.objects.filter(type=App.AppTypeChoices.EXTERNAL)
|
|
|
|
|
|
class AppListAPIView(generics.ListAPIView):
|
|
permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements]
|
|
serializer_class = AppSerializer
|
|
required_alternate_scopes = {
|
|
"GET": [['superapp.applications:list']],
|
|
}
|
|
|
|
def get_queryset(self):
|
|
return App.objects.all()
|
|
|
|
|
|
class AppDetailAPIView(generics.RetrieveAPIView):
|
|
permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements]
|
|
serializer_class = AppSerializer
|
|
lookup_field = 'uuid'
|
|
required_alternate_scopes = {
|
|
"GET": [['superapp.applications:retrieve']],
|
|
}
|
|
|
|
def get_queryset(self):
|
|
return App.objects.all()
|