forked from uncloud/uncloud
Introduce custom ProductViewSet preventing customer from updating
products
This commit is contained in:
parent
33cc2b2111
commit
b3bbfafa04
3 changed files with 19 additions and 3 deletions
|
@ -1,10 +1,11 @@
|
|||
from functools import reduce
|
||||
from rest_framework import mixins
|
||||
from rest_framework.viewsets import GenericViewSet
|
||||
from .models import Bill, Payment, PaymentMethod
|
||||
|
||||
def sum_amounts(entries):
|
||||
return reduce(lambda acc, entry: acc + entry.amount, entries, 0)
|
||||
|
||||
|
||||
def get_balance_for(user):
|
||||
bills = sum_amounts(Bill.objects.filter(owner=user))
|
||||
payments = sum_amounts(Payment.objects.filter(owner=user))
|
||||
|
@ -18,3 +19,14 @@ def get_payment_method_for(user):
|
|||
return method
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class ProductViewSet(mixins.CreateModelMixin,
|
||||
mixins.RetrieveModelMixin,
|
||||
mixins.ListModelMixin,
|
||||
GenericViewSet):
|
||||
"""
|
||||
A customer-facing viewset that provides default `create()`, `retrieve()`
|
||||
and `list()`.
|
||||
"""
|
||||
pass
|
||||
|
|
|
@ -9,6 +9,7 @@ from rest_framework.response import Response
|
|||
from .models import VMHost, VMProduct, VMSnapshotProduct
|
||||
from uncloud_pay.models import Order, RecurringPeriod
|
||||
from .serializers import VMHostSerializer, VMProductSerializer, VMSnapshotProductSerializer
|
||||
from uncloud_pay.helpers import ProductViewSet
|
||||
|
||||
|
||||
import datetime
|
||||
|
@ -19,7 +20,7 @@ class VMHostViewSet(viewsets.ModelViewSet):
|
|||
permission_classes = [permissions.IsAdminUser]
|
||||
|
||||
|
||||
class VMProductViewSet(viewsets.ModelViewSet):
|
||||
class VMProductViewSet(ProductViewSet):
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
serializer_class = VMProductSerializer
|
||||
|
||||
|
|
|
@ -3,12 +3,15 @@ from rest_framework import viewsets, permissions
|
|||
from .models import MatrixServiceProduct
|
||||
from .serializers import MatrixServiceProductSerializer
|
||||
|
||||
class MatrixServiceProductViewSet(viewsets.ModelViewSet):
|
||||
from uncloud_pay.helpers import ProductViewSet
|
||||
|
||||
class MatrixServiceProductViewSet(ProductViewSet):
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
serializer_class = MatrixServiceProductSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
return MatrixServiceProduct.objects.filter(owner=self.request.user)
|
||||
|
||||
def create(self, request):
|
||||
# TODO
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue