Move user view to uncloud_pay

This commit is contained in:
fnux 2020-02-27 12:38:04 +01:00
parent 225f20c91b
commit f5eadd6ddb
4 changed files with 29 additions and 2 deletions

View file

@ -29,6 +29,7 @@ router.register(r'vm/snapshot', vmviews.VMSnapshotProductView, basename='VMSnaps
router.register(r'vm/vm', vmviews.VMProductViewSet, basename='vmproduct')
# Pay
router.register(r'user', payviews.UserViewSet, basename='user')
router.register(r'bill', payviews.BillViewSet, basename='bill')
router.register(r'payment', payviews.PaymentViewSet, basename='payment')

View file

@ -43,9 +43,13 @@ import re
# return Response(products)
class UserViewSet(viewsets.ModelViewSet):
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)

View file

@ -1,3 +1,4 @@
from django.contrib.auth import get_user_model
from rest_framework import serializers
from .models import Bill, Payment
@ -10,3 +11,11 @@ class PaymentSerializer(serializers.ModelSerializer):
class Meta:
model = Payment
fields = ['owner', 'amount', 'source', 'timestamp']
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = get_user_model()
fields = ['username', 'email']
def get_balance(self, obj):
return 666

View file

@ -1,9 +1,11 @@
from django.shortcuts import render
from django.contrib.auth import get_user_model
from rest_framework import viewsets, permissions, status
from rest_framework.response import Response
from rest_framework.decorators import action
from .models import Bill, Payment
from .serializers import BillSerializer, PaymentSerializer
from .serializers import BillSerializer, PaymentSerializer, UserSerializer
from datetime import datetime
###
@ -38,6 +40,17 @@ class PaymentViewSet(viewsets.ReadOnlyModelViewSet):
def get_queryset(self):
return Payment.objects.filter(owner=self.request.user)
class UserViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticated]
def get_queryset(self):
return get_user_model().objects.all()
@action(detail=True)
def balance(self, request):
return Response(status=status.HTTP_204_NO_CONTENT)
###
# Admin views.