From e920fc31e786dd53e0d0c5bfba4abc13d8e435c5 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 15:07:22 +1000 Subject: [PATCH] Only include extra context information if requested --- InvenTree/InvenTree/metadata.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/InvenTree/InvenTree/metadata.py b/InvenTree/InvenTree/metadata.py index 792714e439..bb913e2179 100644 --- a/InvenTree/InvenTree/metadata.py +++ b/InvenTree/InvenTree/metadata.py @@ -9,6 +9,8 @@ from rest_framework.metadata import SimpleMetadata from rest_framework.utils import model_meta from rest_framework.fields import empty +from InvenTree.helpers import str2bool + import users.models @@ -49,12 +51,14 @@ class InvenTreeMetadata(SimpleMetadata): context = {} - if hasattr(self.serializer, 'get_context_data'): - context = self.serializer.get_context_data() - elif hasattr(self.erializer, 'CONTEXT_DATA'): - context = self.serializer.CONTEXT_DATA + if str2bool(request.query_params.get('context', False)): - metadata['context'] = context + if hasattr(self.serializer, 'get_context_data'): + context = self.serializer.get_context_data() + elif hasattr(self.erializer, 'CONTEXT_DATA'): + context = self.serializer.CONTEXT_DATA + + metadata['context'] = context user = request.user