2019-04-27 10:43:27 +00:00
|
|
|
"""
|
|
|
|
Provides a JSON API for the Company app
|
|
|
|
"""
|
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2018-04-23 11:18:35 +00:00
|
|
|
from django_filters.rest_framework import DjangoFilterBackend
|
2018-04-23 09:36:46 +00:00
|
|
|
from rest_framework import filters
|
2018-04-14 04:11:46 +00:00
|
|
|
from rest_framework import generics, permissions
|
2018-04-23 11:10:13 +00:00
|
|
|
|
2019-05-18 10:24:09 +00:00
|
|
|
from django.conf.urls import url, include
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
from .models import Company
|
2019-05-18 08:04:25 +00:00
|
|
|
from .models import SupplierPart, SupplierPriceBreak
|
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
from .serializers import CompanySerializer
|
2019-05-18 08:04:25 +00:00
|
|
|
from .serializers import SupplierPartSerializer, SupplierPriceBreakSerializer
|
2018-04-14 04:11:46 +00:00
|
|
|
|
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
class CompanyList(generics.ListCreateAPIView):
|
2019-04-27 10:43:27 +00:00
|
|
|
""" API endpoint for accessing a list of Company objects
|
|
|
|
|
|
|
|
Provides two methods:
|
|
|
|
|
|
|
|
- GET: Return list of objects
|
|
|
|
- POST: Create a new Company object
|
|
|
|
"""
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
serializer_class = CompanySerializer
|
|
|
|
queryset = Company.objects.all()
|
|
|
|
permission_classes = [
|
|
|
|
permissions.IsAuthenticatedOrReadOnly,
|
|
|
|
]
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
filter_backends = [
|
|
|
|
DjangoFilterBackend,
|
|
|
|
filters.SearchFilter,
|
2018-04-23 10:37:36 +00:00
|
|
|
filters.OrderingFilter,
|
2018-04-23 09:36:46 +00:00
|
|
|
]
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
filter_fields = [
|
2018-04-23 11:10:13 +00:00
|
|
|
'name',
|
|
|
|
'is_customer',
|
|
|
|
'is_supplier',
|
2018-04-23 09:36:46 +00:00
|
|
|
]
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
search_fields = [
|
2018-04-23 11:10:13 +00:00
|
|
|
'name',
|
|
|
|
'description',
|
2018-04-23 09:36:46 +00:00
|
|
|
]
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
ordering_fields = [
|
|
|
|
'name',
|
|
|
|
]
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
ordering = 'name'
|
2018-04-14 04:11:46 +00:00
|
|
|
|
|
|
|
|
2019-04-25 14:10:34 +00:00
|
|
|
class CompanyDetail(generics.RetrieveUpdateDestroyAPIView):
|
2019-04-27 10:43:27 +00:00
|
|
|
""" API endpoint for detail of a single Company object """
|
2019-04-25 14:10:34 +00:00
|
|
|
|
|
|
|
queryset = Company.objects.all()
|
|
|
|
serializer_class = CompanySerializer
|
|
|
|
|
|
|
|
permission_classes = [
|
|
|
|
permissions.IsAuthenticatedOrReadOnly,
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-05-18 10:24:09 +00:00
|
|
|
class SupplierPartList(generics.ListCreateAPIView):
|
|
|
|
""" API endpoint for list view of SupplierPart object
|
|
|
|
|
|
|
|
- GET: Return list of SupplierPart objects
|
|
|
|
- POST: Create a new SupplierPart object
|
|
|
|
"""
|
|
|
|
|
|
|
|
queryset = SupplierPart.objects.all()
|
|
|
|
serializer_class = SupplierPartSerializer
|
|
|
|
|
|
|
|
permission_classes = [
|
|
|
|
permissions.IsAuthenticatedOrReadOnly,
|
|
|
|
]
|
|
|
|
|
|
|
|
filter_backends = [
|
|
|
|
DjangoFilterBackend,
|
|
|
|
filters.SearchFilter,
|
|
|
|
filters.OrderingFilter,
|
|
|
|
]
|
|
|
|
|
|
|
|
filter_fields = [
|
|
|
|
'part',
|
|
|
|
'supplier'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class SupplierPartDetail(generics.RetrieveUpdateDestroyAPIView):
|
|
|
|
""" API endpoint for detail view of SupplierPart object
|
|
|
|
|
|
|
|
- GET: Retrieve detail view
|
|
|
|
- PATCH: Update object
|
|
|
|
- DELETE: Delete objec
|
|
|
|
"""
|
|
|
|
|
|
|
|
queryset = SupplierPart.objects.all()
|
|
|
|
serializer_class = SupplierPartSerializer
|
|
|
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
|
|
|
|
|
|
|
read_only_fields = [
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class SupplierPriceBreakList(generics.ListCreateAPIView):
|
|
|
|
""" API endpoint for list view of SupplierPriceBreak object
|
|
|
|
|
|
|
|
- GET: Retrieve list of SupplierPriceBreak objects
|
|
|
|
- POST: Create a new SupplierPriceBreak object
|
|
|
|
"""
|
|
|
|
|
|
|
|
queryset = SupplierPriceBreak.objects.all()
|
|
|
|
serializer_class = SupplierPriceBreakSerializer
|
|
|
|
|
|
|
|
permission_classes = [
|
|
|
|
permissions.IsAuthenticatedOrReadOnly,
|
|
|
|
]
|
|
|
|
|
|
|
|
filter_backends = [
|
|
|
|
DjangoFilterBackend,
|
|
|
|
]
|
|
|
|
|
|
|
|
filter_fields = [
|
|
|
|
'part',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
supplier_part_api_urls = [
|
|
|
|
|
|
|
|
url(r'^(?P<pk>\d+)/?', SupplierPartDetail.as_view(), name='api-supplier-part-detail'),
|
|
|
|
|
|
|
|
# Catch anything else
|
|
|
|
url(r'^.*$', SupplierPartList.as_view(), name='api-part-supplier-list'),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
company_api_urls = [
|
2019-05-18 10:24:09 +00:00
|
|
|
|
|
|
|
url(r'^part/', include(supplier_part_api_urls)),
|
|
|
|
|
|
|
|
url(r'^price-break/?', SupplierPriceBreakList.as_view(), name='api-part-supplier-price'),
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2019-04-25 14:10:34 +00:00
|
|
|
url(r'^(?P<pk>\d+)/?', CompanyDetail.as_view(), name='api-company-detail'),
|
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
url(r'^.*$', CompanyList.as_view(), name='api-company-list'),
|
2018-04-23 11:18:35 +00:00
|
|
|
]
|