mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-09-16 17:22:32 +03:00
Merge 4de3708a61
into 9dbaac3182
This commit is contained in:
commit
b306b246d6
|
@ -244,16 +244,20 @@ class DocumentingTemplateRenderer(BaseRenderer):
|
||||||
except Exception:
|
except Exception:
|
||||||
form_instance = None
|
form_instance = None
|
||||||
|
|
||||||
# If we still don't have a form instance then try to get an unbound form
|
# Forms for the GET method must be explicit, so do not get an unbound
|
||||||
if not form_instance:
|
# form nor create a generic form for this instance.
|
||||||
try:
|
if method != 'get':
|
||||||
form_instance = view.get_bound_form(method=method)
|
# If we still don't have a form instance then try to get an unbound form
|
||||||
except Exception:
|
if not form_instance:
|
||||||
pass
|
try:
|
||||||
|
form_instance = view.get_bound_form(method=method)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# If we still don't have a form instance then try to get an unbound form which can tunnel arbitrary content types
|
# If we still don't have a form instance then try to get an unbound form
|
||||||
if not form_instance:
|
# which can tunnel arbitrary content types.
|
||||||
form_instance = self._get_generic_content_form(view)
|
if not form_instance:
|
||||||
|
form_instance = self._get_generic_content_form(view)
|
||||||
|
|
||||||
return form_instance
|
return form_instance
|
||||||
|
|
||||||
|
@ -316,6 +320,7 @@ class DocumentingTemplateRenderer(BaseRenderer):
|
||||||
|
|
||||||
content = self._get_content(self.view, self.view.request, obj, media_type)
|
content = self._get_content(self.view, self.view.request, obj, media_type)
|
||||||
|
|
||||||
|
get_form_instance = self._get_form_instance(self.view, 'get')
|
||||||
put_form_instance = self._get_form_instance(self.view, 'put')
|
put_form_instance = self._get_form_instance(self.view, 'put')
|
||||||
post_form_instance = self._get_form_instance(self.view, 'post')
|
post_form_instance = self._get_form_instance(self.view, 'post')
|
||||||
|
|
||||||
|
@ -342,6 +347,7 @@ class DocumentingTemplateRenderer(BaseRenderer):
|
||||||
'version': VERSION,
|
'version': VERSION,
|
||||||
'breadcrumblist': breadcrumb_list,
|
'breadcrumblist': breadcrumb_list,
|
||||||
'available_formats': self.view._rendered_formats,
|
'available_formats': self.view._rendered_formats,
|
||||||
|
'get_form': get_form_instance,
|
||||||
'put_form': put_form_instance,
|
'put_form': put_form_instance,
|
||||||
'post_form': post_form_instance,
|
'post_form': post_form_instance,
|
||||||
'FORMAT_PARAM': self._FORMAT_QUERY_PARAM,
|
'FORMAT_PARAM': self._FORMAT_QUERY_PARAM,
|
||||||
|
|
|
@ -182,15 +182,19 @@ class FormResource(Resource):
|
||||||
"""
|
"""
|
||||||
Returns the form class used to validate this resource.
|
Returns the form class used to validate this resource.
|
||||||
"""
|
"""
|
||||||
# A form on the view overrides a form on the resource.
|
|
||||||
form = getattr(self.view, 'form', None) or self.form
|
|
||||||
|
|
||||||
# Use the requested method or determine the request method
|
# Use the requested method or determine the request method
|
||||||
if method is None and hasattr(self.view, 'request') and hasattr(self.view, 'method'):
|
if method is None and hasattr(self.view, 'request') and hasattr(self.view, 'method'):
|
||||||
method = self.view.method
|
method = self.view.method
|
||||||
elif method is None and hasattr(self.view, 'request'):
|
elif method is None and hasattr(self.view, 'request'):
|
||||||
method = self.view.request.method
|
method = self.view.request.method
|
||||||
|
|
||||||
|
# A form on the view overrides a form on the resource. The GET method
|
||||||
|
# must have its form explicity set (e.g., get_form).
|
||||||
|
if not method or method.lower() != 'get':
|
||||||
|
form = getattr(self.view, 'form', None) or self.form
|
||||||
|
else:
|
||||||
|
form = None
|
||||||
|
|
||||||
# A method form on the view or resource overrides the general case.
|
# A method form on the view or resource overrides the general case.
|
||||||
# Method forms are attributes like `get_form` `post_form` `put_form`.
|
# Method forms are attributes like `get_form` `post_form` `put_form`.
|
||||||
if method:
|
if method:
|
||||||
|
|
|
@ -179,7 +179,8 @@ class Serializer(object):
|
||||||
stack = self.stack[:]
|
stack = self.stack[:]
|
||||||
stack.append(obj)
|
stack.append(obj)
|
||||||
|
|
||||||
return related_serializer(depth=depth, stack=stack).serialize(obj)
|
return related_serializer(depth=depth, stack=stack).serialize(
|
||||||
|
obj, request=self.request)
|
||||||
|
|
||||||
def serialize_max_depth(self, obj):
|
def serialize_max_depth(self, obj):
|
||||||
"""
|
"""
|
||||||
|
@ -258,6 +259,10 @@ class Serializer(object):
|
||||||
Convert any object into a serializable representation.
|
Convert any object into a serializable representation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Request from related serializer.
|
||||||
|
if request is not None:
|
||||||
|
self.request = request
|
||||||
|
|
||||||
if isinstance(obj, (dict, models.Model)):
|
if isinstance(obj, (dict, models.Model)):
|
||||||
# Model instances & dictionaries
|
# Model instances & dictionaries
|
||||||
return self.serialize_model(obj)
|
return self.serialize_model(obj)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user