2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-16 09:46:31 +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:
Oliver
2018-05-05 00:51:17 +10:00
parent ee347c6165
commit 41e031d4b4
5 changed files with 35 additions and 5 deletions

View 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

View File

@@ -92,7 +92,8 @@ TEMPLATES = [
]
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',
# 'PAGE_SIZE': 50,
}