uncloud-mravi/uncloud/uncloud_api/views.py

55 lines
1.6 KiB
Python

from django.shortcuts import render
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from rest_framework import viewsets, permissions, generics
from rest_framework.views import APIView
from rest_framework.response import Response
from .serializers import UserSerializer
import inspect
import sys
import re
# maybe drop or not --- we need something to guide the user!
# class ProductsViewSet(viewsets.ViewSet):
# permission_classes = [permissions.IsAuthenticated]
# def list(self, request):
# clsmembers = []
# for modules in [ 'uncloud_api.models', 'uncloud_vm.models' ]:
# clsmembers.extend(inspect.getmembers(sys.modules[modules], inspect.isclass))
# products = []
# for name, c in clsmembers:
# # Include everything that ends in Product, but not Product itself
# m = re.match(r'(?P<pname>.+)Product$', name)
# if m:
# products.append({
# 'name': m.group('pname'),
# 'description': c.description,
# 'recurring_period': c.recurring_period,
# 'pricing_model': c.pricing_model()
# }
# )
# return Response(products)
class UserViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticated]
def get_queryset(self):
return self.request.user
@action(detail=True)
def balance(self, request):
return Response(status=status.HTTP_204_NO_CONTENT)