2020-02-20 15:52:50 +00:00
|
|
|
from django.shortcuts import render
|
2020-02-21 10:32:41 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.contrib.auth.models import Group
|
2020-02-20 15:52:50 +00:00
|
|
|
|
2020-02-21 23:22:42 +00:00
|
|
|
from rest_framework import viewsets, permissions, generics
|
2020-02-25 19:53:12 +00:00
|
|
|
|
2020-02-21 23:22:42 +00:00
|
|
|
from rest_framework.views import APIView
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
2020-02-27 10:40:36 +00:00
|
|
|
from .serializers import UserSerializer
|
2020-02-25 19:53:12 +00:00
|
|
|
|
2020-02-25 13:12:23 +00:00
|
|
|
import inspect
|
|
|
|
import sys
|
|
|
|
import re
|
2020-02-20 17:58:07 +00:00
|
|
|
|
2020-02-25 19:53:12 +00:00
|
|
|
|
2020-02-25 21:01:55 +00:00
|
|
|
|
|
|
|
# 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.ModelViewSet):
|
|
|
|
serializer_class = UserSerializer
|
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
|
|
|
|
|
|
def get_queryset(self):
|
2020-02-27 10:40:36 +00:00
|
|
|
return self.request.user
|