@@ -282,10 +282,8 @@ def get_link(self, path, method, generator):
282
282
fields += self .get_pagination_fields (path , method )
283
283
fields += self .get_filter_fields (path , method )
284
284
285
- # TEMP: now we proxy back to the generator
286
-
287
285
if fields and any ([field .location in ('form' , 'body' ) for field in fields ]):
288
- encoding = generator .get_encoding (path , method , view )
286
+ encoding = self .get_encoding (path , method )
289
287
else :
290
288
encoding = None
291
289
@@ -456,6 +454,29 @@ def get_filter_fields(self, path, method):
456
454
fields += filter_backend ().get_schema_fields (view )
457
455
return fields
458
456
457
+ def get_encoding (self , path , method ):
458
+ """
459
+ Return the 'encoding' parameter to use for a given endpoint.
460
+ """
461
+ view = self .view
462
+
463
+ # Core API supports the following request encodings over HTTP...
464
+ supported_media_types = set ((
465
+ 'application/json' ,
466
+ 'application/x-www-form-urlencoded' ,
467
+ 'multipart/form-data' ,
468
+ ))
469
+ parser_classes = getattr (view , 'parser_classes' , [])
470
+ for parser_class in parser_classes :
471
+ media_type = getattr (parser_class , 'media_type' , None )
472
+ if media_type in supported_media_types :
473
+ return media_type
474
+ # Raw binary uploads are supported with "application/octet-stream"
475
+ if media_type == '*/*' :
476
+ return 'application/octet-stream'
477
+
478
+ return None
479
+
459
480
# TODO: Where should this live?
460
481
# - We import APIView here. So we can't import the descriptor into `views`
461
482
# - APIView is only used by SchemaView.
@@ -640,29 +661,6 @@ def coerce_path(self, path, method, view):
640
661
field_name = 'id'
641
662
return path .replace ('{pk}' , '{%s}' % field_name )
642
663
643
- # Methods for generating each individual `Link` instance...
644
-
645
- def get_encoding (self , path , method , view ):
646
- """
647
- Return the 'encoding' parameter to use for a given endpoint.
648
- """
649
- # Core API supports the following request encodings over HTTP...
650
- supported_media_types = set ((
651
- 'application/json' ,
652
- 'application/x-www-form-urlencoded' ,
653
- 'multipart/form-data' ,
654
- ))
655
- parser_classes = getattr (view , 'parser_classes' , [])
656
- for parser_class in parser_classes :
657
- media_type = getattr (parser_class , 'media_type' , None )
658
- if media_type in supported_media_types :
659
- return media_type
660
- # Raw binary uploads are supported with "application/octet-stream"
661
- if media_type == '*/*' :
662
- return 'application/octet-stream'
663
-
664
- return None
665
-
666
664
# Method for generating the link layout....
667
665
668
666
def get_keys (self , subpath , method , view ):
0 commit comments