Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix library upload not working due to unsupported content-type in DRF #130

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions backend/library/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
from .serializers import LibrarySerializer, LibraryUploadSerializer
from .utils import get_available_libraries, get_library, import_library_view


class LibraryViewSet(BaseModelViewSet):
serializer_class = LibrarySerializer
parser_classes = [FileUploadParser]

# solve issue with URN containing dot, see https://stackoverflow.com/questions/27963899/django-rest-framework-using-dot-in-url
lookup_value_regex = r"[\w.:-]+"
Expand Down Expand Up @@ -127,12 +127,8 @@ def import_library(self, request, pk=None):
status=HTTP_422_UNPROCESSABLE_ENTITY,
)


class UploadLibraryView(APIView):
parser_classes = (FileUploadParser,)
serializer_class = LibraryUploadSerializer

def post(self, request):
@action(detail=False, methods=["post"], url_path="upload")
def upload_library(self, request):
if not request.data:
return HttpResponse(
json.dumps({"error": "No file detected !"}), status=HTTP_400_BAD_REQUEST
Expand Down
Loading