Skip to content

Commit

Permalink
Update MultiPartJSONParser
Browse files Browse the repository at this point in the history
  • Loading branch information
EXG1O committed May 10, 2024
1 parent e2097d9 commit aee5e0b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions constructor_telegram_bots/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from rest_framework.exceptions import ParseError
from rest_framework.parsers import DataAndFiles, MultiPartParser

from itertools import chain
from json import JSONDecodeError
from typing import Any
import json
Expand All @@ -15,13 +16,13 @@ def parse(self, *args: Any, **kwargs: Any) -> dict[str, Any]: # type: ignore [o
parsed: DataAndFiles = super().parse(*args, **kwargs) # type: ignore [type-arg]

try:
data: dict[str, Any] = json.loads(parsed.data['data'])
data: dict[str, Any] = json.loads(parsed.data.pop('data'))
except (KeyError, JSONDecodeError):
raise ParseError()

data.update({'images': [], 'images_id': [], 'files': [], 'files_id': []})

for key, value in parsed.files.items():
for key, value in chain(parsed.data.items(), parsed.files.items()):
try:
name: str = key.split(':')[0]
except IndexError:
Expand Down

0 comments on commit aee5e0b

Please sign in to comment.