mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Draft API endpoint RUD class
- RUD = Retrieve / Update / Destroy - When issuing an Update command, the validity is checked but the model object is only saved if the POST data has "_is_final": true
This commit is contained in:
parent
ee347c6165
commit
41e031d4b4
17
InvenTree/InvenTree/serializers.py
Normal file
17
InvenTree/InvenTree/serializers.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from rest_framework import serializers
|
||||||
|
from rest_framework import generics
|
||||||
|
from rest_framework import mixins
|
||||||
|
|
||||||
|
class DraftRUDView(generics.RetrieveAPIView, generics.UpdateAPIView, generics.DestroyAPIView):
|
||||||
|
|
||||||
|
def perform_update(self, serializer):
|
||||||
|
|
||||||
|
ctx_data = serializer._context['request'].data
|
||||||
|
|
||||||
|
if ctx_data.get('_is_final', False) in [True, u'true', u'True', 1]:
|
||||||
|
super(generics.UpdateAPIView, self).perform_update(serializer)
|
||||||
|
else:
|
||||||
|
pass
|
@ -92,7 +92,8 @@ TEMPLATES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'EXCEPTION_HANDLER': 'InvenTree.utils.api_exception_handler',
|
'EXCEPTION_HANDLER': 'rest_framework.views.exception_handler'
|
||||||
|
# 'EXCEPTION_HANDLER': 'InvenTree.utils.api_exception_handler',
|
||||||
# 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
# 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||||
# 'PAGE_SIZE': 50,
|
# 'PAGE_SIZE': 50,
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django_filters.rest_framework import DjangoFilterBackend
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
from rest_framework import filters
|
from rest_framework import filters
|
||||||
from rest_framework import generics, permissions
|
from rest_framework import generics, permissions, mixins
|
||||||
|
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
|
|
||||||
@ -15,6 +15,7 @@ from .serializers import SupplierPartSerializer
|
|||||||
from .serializers import CategorySerializer
|
from .serializers import CategorySerializer
|
||||||
|
|
||||||
from InvenTree.views import TreeSerializer
|
from InvenTree.views import TreeSerializer
|
||||||
|
from InvenTree.serializers import DraftRUDView
|
||||||
|
|
||||||
class PartCategoryTree(TreeSerializer):
|
class PartCategoryTree(TreeSerializer):
|
||||||
|
|
||||||
@ -52,6 +53,14 @@ class CategoryList(generics.ListCreateAPIView):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class PartDetail(DraftRUDView):
|
||||||
|
queryset = Part.objects.all()
|
||||||
|
serializer_class = PartSerializer
|
||||||
|
|
||||||
|
permission_classes = [
|
||||||
|
permissions.IsAuthenticatedOrReadOnly,
|
||||||
|
]
|
||||||
|
|
||||||
class PartList(generics.ListCreateAPIView):
|
class PartList(generics.ListCreateAPIView):
|
||||||
|
|
||||||
queryset = Part.objects.all()
|
queryset = Part.objects.all()
|
||||||
@ -137,5 +146,8 @@ part_api_urls = [
|
|||||||
|
|
||||||
url(r'^supplier/?', SupplierPartList.as_view(), name='api-part-supplier-list'),
|
url(r'^supplier/?', SupplierPartList.as_view(), name='api-part-supplier-list'),
|
||||||
url(r'^bom/?', BomList.as_view(), name='api-bom-list'),
|
url(r'^bom/?', BomList.as_view(), name='api-bom-list'),
|
||||||
|
|
||||||
|
url(r'^(?P<pk>\d+)/', PartDetail.as_view(), name='api-part-detail'),
|
||||||
|
|
||||||
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
||||||
]
|
]
|
||||||
|
@ -11,14 +11,14 @@ from .serializers import StockItemSerializer, StockQuantitySerializer
|
|||||||
from .serializers import LocationSerializer
|
from .serializers import LocationSerializer
|
||||||
|
|
||||||
from InvenTree.views import TreeSerializer
|
from InvenTree.views import TreeSerializer
|
||||||
|
from InvenTree.serializers import DraftRUDView
|
||||||
|
|
||||||
class StockCategoryTree(TreeSerializer):
|
class StockCategoryTree(TreeSerializer):
|
||||||
title = 'Stock'
|
title = 'Stock'
|
||||||
model = StockLocation
|
model = StockLocation
|
||||||
|
|
||||||
|
|
||||||
class StockDetail(generics.RetrieveUpdateDestroyAPIView):
|
class StockDetail(DraftRUDView):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
get:
|
get:
|
||||||
|
@ -56,7 +56,7 @@ class StockItemSerializer(serializers.ModelSerializer):
|
|||||||
'stocktake_date',
|
'stocktake_date',
|
||||||
'stocktake_user',
|
'stocktake_user',
|
||||||
'updated',
|
'updated',
|
||||||
'quantity',
|
#'quantity',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user