78 lines
2.4 KiB
Python
78 lines
2.4 KiB
Python
from django.shortcuts import render
|
|
from rest_framework import viewsets, mixins
|
|
from .models import Account, Bank, Institution, Transaction, Slice, Rule
|
|
from connection.models import Connection, ConnectionType
|
|
from api.serializers import (AccountSerializer,
|
|
BankSerializer, BankSerializerPOST,
|
|
InstitutionSerializer,
|
|
TransactionSerializer,
|
|
ConnectionSerializer,
|
|
ConnectionTypeSerializer,
|
|
SliceSerializer,
|
|
RuleSerializer)
|
|
|
|
|
|
class AccountViewSet(viewsets.ModelViewSet):
|
|
"""API endpoint that allows accounts to be viewed or edited
|
|
"""
|
|
queryset = Account.objects.all()
|
|
serializer_class = AccountSerializer
|
|
|
|
|
|
class BankViewSet(viewsets.ModelViewSet):
|
|
"""API endpoint that allows Banks to be viewed or edited
|
|
"""
|
|
queryset = Bank.objects.all()
|
|
# serializer_class = BankSerializer
|
|
|
|
def get_serializer_class(self):
|
|
if self.action == 'create':
|
|
return BankSerializerPOST
|
|
return BankSerializer
|
|
|
|
|
|
class InstitutionViewSet(viewsets.ReadOnlyModelViewSet):
|
|
"""API endpoint that allows Banks to be viewed.
|
|
"""
|
|
queryset = Institution.objects.all()
|
|
serializer_class = InstitutionSerializer
|
|
|
|
|
|
class TransactionViewSet(viewsets.ReadOnlyModelViewSet):
|
|
"""API endpoint that allows Banks to be viewed.
|
|
"""
|
|
queryset = Transaction.objects.all()
|
|
serializer_class = TransactionSerializer
|
|
|
|
|
|
class ConnectionTypeViewSet(viewsets.ModelViewSet):
|
|
queryset = ConnectionType.objects.all()
|
|
serializer_class = ConnectionTypeSerializer
|
|
|
|
|
|
class ConnectionViewSet(viewsets.ModelViewSet):
|
|
"""API endpoint that allows connections to be seen or created
|
|
"""
|
|
queryset = Connection.objects.all()
|
|
serializer_class = ConnectionSerializer
|
|
# Make connections somewhat immutable from the users perspective
|
|
http_method_names = [
|
|
'get',
|
|
'post',
|
|
'delete',
|
|
'options']
|
|
|
|
|
|
class SliceViewSet(viewsets.ReadOnlyModelViewSet):
|
|
"""API endpoint that allows Banks to be viewed.
|
|
"""
|
|
queryset = Slice.objects.all()
|
|
serializer_class = SliceSerializer
|
|
|
|
|
|
class RuleViewSet(viewsets.ReadOnlyModelViewSet):
|
|
"""API endpoint that allows Banks to be viewed.
|
|
"""
|
|
queryset = Rule.objects.all()
|
|
serializer_class = RuleSerializer
|