forked from uncloud/uncloud
vmhosts, restructure urls, etc.
This commit is contained in:
parent
d4b170f813
commit
c7ded96658
9 changed files with 134 additions and 47 deletions
|
|
@ -5,11 +5,10 @@ from rest_framework import serializers
|
|||
|
||||
from .models import VMSnapshotProduct
|
||||
|
||||
|
||||
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = ['url', 'username', 'email', 'groups']
|
||||
fields = ['url', 'username', 'email']
|
||||
|
||||
class GroupSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
|
|
|
|||
|
|
@ -17,18 +17,6 @@ import sys
|
|||
import re
|
||||
|
||||
|
||||
|
||||
class UserViewSet(viewsets.ModelViewSet):
|
||||
|
||||
"""
|
||||
API endpoint that allows users to be viewed or edited.
|
||||
"""
|
||||
queryset = get_user_model().objects.all().order_by('-date_joined')
|
||||
serializer_class = UserSerializer
|
||||
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
|
||||
# POST /vm/snapshot/ vmuuid=... => create snapshot, returns snapshot uuid
|
||||
# GET /vm/snapshot => list
|
||||
# DEL /vm/snapshot/<uuid:uuid> => delete
|
||||
|
|
@ -69,23 +57,38 @@ class VMSnapshotView(viewsets.ViewSet):
|
|||
return Response(serializer.data)
|
||||
|
||||
|
||||
# Next: create /order/<productname> urls
|
||||
# Next: strip off "Product" at the end
|
||||
class ProductsView(APIView):
|
||||
def get(self, request, format=None):
|
||||
clsmembers = inspect.getmembers(sys.modules['uncloud_api.models'], 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()
|
||||
}
|
||||
)
|
||||
|
||||
# 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))
|
||||
|
||||
|
||||
return Response(products)
|
||||
# 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):
|
||||
return self.request.user
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue