| @@ -1,7 +1,13 @@ | |||||
| from django.urls import path | |||||
| from django.urls import path, include | |||||
| from . import views | from . import views | ||||
| from rest_framework import routers | |||||
| router = routers.DefaultRouter() | |||||
| router.register(r'items', views.ItemViewSet) | |||||
| router.register(r'invoices', views.InvoiceViewSet) | |||||
| urlpatterns = [ | urlpatterns = [ | ||||
| path('invoices/', views.InvoiceList.as_view()), | |||||
| path('invoice-items/<int:invoice_key>/', views.ItemList.as_view()), | |||||
| path('', include(router.urls)), | |||||
| ] | ] | ||||
| @@ -1,27 +1,19 @@ | |||||
| from rest_framework.response import Response | |||||
| from rest_framework.views import APIView | |||||
| from rest_framework import viewsets | |||||
| from rest_framework.authentication import TokenAuthentication, SessionAuthentication | from rest_framework.authentication import TokenAuthentication, SessionAuthentication | ||||
| from rest_framework.permissions import IsAuthenticated | from rest_framework.permissions import IsAuthenticated | ||||
| from .models import Item, Invoice | from .models import Item, Invoice | ||||
| from .serializers import ItemSerializer, InvoiceSerializer | from .serializers import ItemSerializer, InvoiceSerializer | ||||
| class ItemList(APIView): | |||||
| class ItemViewSet(viewsets.ModelViewSet): | |||||
| queryset = Item.objects.all() | |||||
| serializer_class = ItemSerializer | |||||
| authentication_classes = [TokenAuthentication, SessionAuthentication] | authentication_classes = [TokenAuthentication, SessionAuthentication] | ||||
| permission_classes = [IsAuthenticated] | permission_classes = [IsAuthenticated] | ||||
| def get(self, request, invoice_key): | |||||
| items = Item.objects.filter(invoice=invoice_key) | |||||
| serializer = ItemSerializer(items, many=True) | |||||
| return Response(serializer.data) | |||||
| class InvoiceList(APIView): | |||||
| class InvoiceViewSet(viewsets.ModelViewSet): | |||||
| queryset = Invoice.objects.all() | |||||
| serializer_class = InvoiceSerializer | |||||
| authentication_classes = [TokenAuthentication, SessionAuthentication] | authentication_classes = [TokenAuthentication, SessionAuthentication] | ||||
| permission_classes = [IsAuthenticated] | permission_classes = [IsAuthenticated] | ||||
| def get(self, request): | |||||
| invoices = Invoice.objects.all() | |||||
| invoice_serializer = InvoiceSerializer(invoices, many=True) | |||||
| return Response(invoice_serializer.data) | |||||
| @@ -1,6 +1,12 @@ | |||||
| from django.urls import path | |||||
| from django.urls import path, include | |||||
| from . import views | from . import views | ||||
| from rest_framework import routers | |||||
| router = routers.DefaultRouter() | |||||
| router.register(r'projects', views.ProjectViewSet) | |||||
| urlpatterns = [ | urlpatterns = [ | ||||
| path('projects/', views.ProjectList.as_view()), | |||||
| path('', include(router.urls)), | |||||
| ] | ] | ||||
| @@ -1,16 +1,12 @@ | |||||
| from rest_framework.response import Response | |||||
| from rest_framework.views import APIView | |||||
| from rest_framework import viewsets | |||||
| from rest_framework.authentication import TokenAuthentication, SessionAuthentication | from rest_framework.authentication import TokenAuthentication, SessionAuthentication | ||||
| from rest_framework.permissions import IsAuthenticated | from rest_framework.permissions import IsAuthenticated | ||||
| from .models import Project | from .models import Project | ||||
| from .serializers import ProjectSerializer | from .serializers import ProjectSerializer | ||||
| class ProjectList(APIView): | |||||
| class ProjectViewSet(viewsets.ReadOnlyModelViewSet): | |||||
| queryset = Project.objects.all() | |||||
| serializer_class = ProjectSerializer | |||||
| authentication_classes = [TokenAuthentication, SessionAuthentication] | authentication_classes = [TokenAuthentication, SessionAuthentication] | ||||
| permission_classes = [IsAuthenticated] | permission_classes = [IsAuthenticated] | ||||
| def get(self, request): | |||||
| projects = Project.objects.all() | |||||
| serializer = ProjectSerializer(projects, many=True) | |||||
| return Response(serializer.data) | |||||
| @@ -1,7 +1,12 @@ | |||||
| from django.urls import path | |||||
| from django.urls import path, include | |||||
| from . import views | from . import views | ||||
| from rest_framework import routers | |||||
| router = routers.DefaultRouter() | |||||
| router.register(r'representatives', views.RepresentativeViewSet) | |||||
| urlpatterns = [ | urlpatterns = [ | ||||
| path('representative-roles/', views.RoleList.as_view()), | |||||
| path('representatives/', views.RepresentativeList.as_view()), | |||||
| path('', include(router.urls)), | |||||
| ] | ] | ||||
| @@ -1,26 +1,20 @@ | |||||
| from rest_framework.response import Response | |||||
| from rest_framework.views import APIView | |||||
| from rest_framework import viewsets | |||||
| from rest_framework.authentication import TokenAuthentication, SessionAuthentication | from rest_framework.authentication import TokenAuthentication, SessionAuthentication | ||||
| from rest_framework.permissions import IsAuthenticated | from rest_framework.permissions import IsAuthenticated | ||||
| from .models import Representative, Role | from .models import Representative, Role | ||||
| from .serializers import RoleSerializer, RepresentativeSerializer | from .serializers import RoleSerializer, RepresentativeSerializer | ||||
| class RoleList(APIView): | |||||
| class RoleViewSet(viewsets.ReadOnlyModelViewSet): | |||||
| queryset = Role.objects.all() | |||||
| serializer_class = RoleSerializer | |||||
| authentication_classes = [TokenAuthentication, SessionAuthentication] | authentication_classes = [TokenAuthentication, SessionAuthentication] | ||||
| permission_classes = [IsAuthenticated] | permission_classes = [IsAuthenticated] | ||||
| def get(self, request): | |||||
| roles = Role.objects.all() | |||||
| serializer = RoleSerializer(roles, many=True) | |||||
| return Response(serializer.data) | |||||
| class RepresentativeList(APIView): | |||||
| class RepresentativeViewSet(viewsets.ReadOnlyModelViewSet): | |||||
| queryset = Representative.objects.all() | |||||
| serializer_class = RepresentativeSerializer | |||||
| authentication_classes = [TokenAuthentication, SessionAuthentication] | authentication_classes = [TokenAuthentication, SessionAuthentication] | ||||
| permission_classes = [IsAuthenticated] | permission_classes = [IsAuthenticated] | ||||
| def get(self, request): | |||||
| representatives = Representative.objects.all() | |||||
| serializer = RepresentativeSerializer(representatives, many=True) | |||||
| return Response(serializer.data) | |||||