Skip to content
Snippets Groups Projects
Commit ba4326a0 authored by Haakon Gunleiksrud's avatar Haakon Gunleiksrud
Browse files

Fix smells in workouts/parsers.py

parent edd21ecd
No related branches found
No related tags found
2 merge requests!31Complete exercise 3,!29Hg backend smells
Pipeline #128973 passed
"""Contains custom parsers for serializers from the workouts Django app
"""
import json
from rest_framework import parsers
# Thanks to https://stackoverflow.com/a/50514630
class MultipartJsonParser(parsers.MultiPartParser):
"""Parser for serializing multipart data containing both files and JSON.
This is currently unused.
"""
Parser for serializing multipart data containing both files and JSON.
"""
def parse(self, stream, media_type=None, parser_context=None):
......@@ -22,8 +18,7 @@ class MultipartJsonParser(parsers.MultiPartParser):
for key, value in result.data.items():
if not isinstance(value, str):
data[key] = value
continue
if "{" in value or "[" in value:
elif "{" in value or "[" in value:
try:
data[key] = json.loads(value)
except ValueError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment