@@ -4,7 +4,7 @@ def get_request_data(request, key, default_value=None):
4
4
"""
5
5
Extracts data from request.data, request.FILES, and request.query_params based on the request method and content type.
6
6
7
- :param request: DRF request object
7
+ :param request: Petra request object
8
8
:param key: The key to look for in the request data
9
9
:param default_value: The default value to return if the key is not found
10
10
:return: The value associated with the key, or the default value if not found
@@ -31,3 +31,30 @@ def get_request_data(request, key, default_value=None):
31
31
return default_value
32
32
except Exception as e :
33
33
raise ParseError (f"Error extracting request data for key '{ key } ': { str (e )} " )
34
+
35
+ def get_all_request_data (request ):
36
+ """
37
+ Combines all request data from query_params, request.data, and FILES into a single dictionary.
38
+
39
+ :param request: Petra request object
40
+ :return: Dictionary containing all request data
41
+ """
42
+ try :
43
+ combined_data = {}
44
+
45
+ # Add query parameters
46
+ combined_data .update (request .query_params .dict ())
47
+
48
+ # Add request data for POST/PUT/PATCH methods
49
+ if request .method in ['POST' , 'PUT' , 'PATCH' ]:
50
+ if request .content_type .startswith ('multipart/form-data' ):
51
+ # Add both form data and files
52
+ combined_data .update (request .data .dict ())
53
+ combined_data .update (request .FILES .dict ())
54
+ elif request .content_type in ['application/json' , 'application/x-www-form-urlencoded' ]:
55
+ # Add JSON or form-encoded data
56
+ combined_data .update (request .data )
57
+
58
+ return combined_data
59
+ except Exception as e :
60
+ raise ParseError (f"Error extracting all request data: { str (e )} " )
0 commit comments