From 5b08e04be0368d977a4a8581c5c38b8e99226f84 Mon Sep 17 00:00:00 2001 From: Gergely Date: Mon, 2 Oct 2023 14:57:40 +0200 Subject: [PATCH] foo --- binder/views.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/binder/views.py b/binder/views.py index 3ec6ac20..8017041e 100644 --- a/binder/views.py +++ b/binder/views.py @@ -1830,21 +1830,25 @@ def _store_m2m_field(self, obj, field, value, request): def _resolve_file_path(self, value, request): match = re.match(r'/api/(\w+)/(\d+)/(\w+)/', value) if not match: + print('no match') return None model, pk, field = match.groups() try: model = self.router.name_models[model] except KeyError: + print('KeyError') return None view = self.get_model_view(model) if field not in view.file_fields: + print('not in') return None try: obj = view.get_queryset(request).get(pk=pk) except model.DoesNotExist: + print('doesnt exist') return None value = getattr(obj, field) @@ -2023,11 +2027,15 @@ def _store_field(self, obj, field, value, request, pk=None): elif isinstance(f, models.FileField): # If the value is a str that matches how we return file # fields we convert it to the correct file + + print(f'value: {value}') if isinstance(value, str): value_ = self._resolve_file_path(value, request) + print(f'value_: {value_}') if value_ is not None: value = value_ + print(f'processed value: {value}') if not isinstance(value, File) and value is not None: raise BinderFieldTypeError(self.model.__name__, field) @@ -2774,6 +2782,7 @@ def dispatch_file_field(self, request, pk=None, file_field=None): try: # Take an arbitrary uploaded file file = next(request.FILES.values()) + print(f'file: {file}') except StopIteration: raise BinderRequestError('File POST should use multipart/form-data (with an arbitrary key for the file data).') @@ -2784,6 +2793,8 @@ def dispatch_file_field(self, request, pk=None, file_field=None): field = self.model._meta.get_field(file_field_name) path = self.router.model_route(self.model, obj.id, field) + print(f'field: {field}') + print(f'path: {path}') # {duplicate-binder-file-field-hash-code} if isinstance(field, BinderFileField): file_field = getattr(obj, file_field_name)