Coverage for rest_framework/renderers : + 92% +
+
+ From 3d4bb4b5533fa281c2f11c12ceb0a9ae61aa0d54 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 21 Jun 2013 22:03:07 +0100 Subject: Ensure action kwargs properly handdled. Refs #940. --- htmlcov/rest_framework_renderers.html | 1227 +++++++++++++++++++++++++++++++++ 1 file changed, 1227 insertions(+) create mode 100644 htmlcov/rest_framework_renderers.html (limited to 'htmlcov/rest_framework_renderers.html') diff --git a/htmlcov/rest_framework_renderers.html b/htmlcov/rest_framework_renderers.html new file mode 100644 index 00000000..58c71b85 --- /dev/null +++ b/htmlcov/rest_framework_renderers.html @@ -0,0 +1,1227 @@ + + +
+ + + + +
+
+Hot-keys on this page
++ r + m + x + p toggle line displays +
++ j + k next/prev highlighted chunk +
++ 0 (zero) top of page +
++ 1 (one) first highlighted chunk +
+| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | +
+ """ +Renderers are used to serialize a response into specific media types. ++ They give us a generic way of being able to handle various media types +on the response, such as JSON encoded data or HTML output. ++ REST framework also provides an HTML renderer the renders the browsable API. +""" + ++ + + + + + + + + + + + + + + + + + + + + """ +All renderers should extend this class, setting the `media_type` +and `format` attributes, and override the `.render()` method. +""" ++ + + + + + raise NotImplemented('Renderer class requires .render() to be implemented') ++ + + """ +Renderer which serializes to JSON. +Applies JSON's backslash-u character escaping for non-ascii characters. +""" ++ + + + + + # Note that JSON encodings must be utf-8, utf-16 or utf-32. +# See: http://www.ietf.org/rfc/rfc4627.txt ++ + """ +Render `data` into JSON. +""" + + ++ # If 'indent' is provided in the context, then pretty print the result. +# E.g. If we're being called by the BrowsableAPIRenderer. + + ++ + # If the media type looks like 'application/json; indent=4', +# then pretty print the result. + + + + + + ++ + indent=indent, ensure_ascii=self.ensure_ascii) ++ # On python 2.x json.dumps() returns bytestrings if ensure_ascii=True, +# but if ensure_ascii=False, the return type is underspecified, +# and may (or may not) be unicode. +# On python 3.x json.dumps() returns unicode strings. + + + ++ + + + + + Renderer which serializes to JSON. +Does *not* apply JSON's character escaping for non-ascii characters. +""" ++ + + """ +Renderer which serializes to json, +wrapping the json output in a callback function. +""" ++ + + + + + + """ +Determine the name of the callback to wrap around the json output. +""" + + + ++ + """ +Renders into jsonp, wrapping the json output in a callback function. ++ Clients may set the callback function name using a query parameter +on the URL, for example: ?callback=exampleCallbackName +""" + + + +renderer_context) + ++ + + """ +Renderer which serializes to XML. +""" ++ + + + + + """ +Renders *obj* into serialized XML. +""" + +return '' ++ + + + + + + + + + + + + + + + + + + + + + + + + + + # Don't output any value + ++ else: + ++ + + """ +Renderer which serializes to YAML. +""" ++ + + + + + + """ +Renders *obj* into serialized YAML. +""" + ++ + return '' ++ + + + + """ +An HTML renderer for use with templates. ++ The data supplied to the Response object should be a dictionary that will +be used as context for the template. ++ The template name is determined by (in order of preference): ++ 1. An explicit `.template_name` attribute set on the response. +2. An explicit `.template_name` attribute set on this class. +3. The return result of calling `view.get_template_names()`. ++ For example: +data = {'users': User.objects.all()} +return Response(data, template_name='users.html') ++ For pre-rendered HTML, see StaticHTMLRenderer. +""" ++ + + + + '%(status_code)s.html', +'api_exception.html' +] + ++ + """ +Renders data to HTML, using Django's standard template rendering. ++ The template name is determined by (in order of preference): ++ 1. An explicit .template_name set on the response. +2. An explicit .template_name set on this class. +3. The return result of calling view.get_template_names(). +""" + + + + ++ + + else: + + ++ + + + + + + + + + + + + + + elif self.template_name: +return [self.template_name] +elif hasattr(view, 'get_template_names'): +return view.get_template_names() +raise ImproperlyConfigured('Returned a template response with no template_name') ++ + + for name in self.exception_template_names] ++ + # Try to find an appropriate error template + + +# Fall back to using eg '404 Not Found' + +response.status_text.title())) ++ + # Note, subclass TemplateHTMLRenderer simply for the exception behavior + +""" +An HTML renderer class that simply returns pre-rendered HTML. ++ The data supplied to the Response object should be a string representing +the pre-rendered HTML content. ++ For example: +data = '<html><body>example</body></html>' +return Response(data) ++ For template rendered HTML, see TemplateHTMLRenderer. +""" + + + ++ + renderer_context = renderer_context or {} +response = renderer_context['response'] ++ if response and response.exception: +request = renderer_context['request'] +template = self.get_exception_template(response) +context = self.resolve_context(data, request, response) +return template.render(context) ++ return data ++ + + """ +HTML renderer used to self-document the API. +""" + + + + ++ + """ +Return an instance of the first valid renderer. +(Don't use another documenting renderer.) +""" + +if not issubclass(renderer, BrowsableAPIRenderer)] + + + ++ + accepted_media_type, renderer_context): +""" +Get the content as if it had been rendered by the default +non-documenting renderer. +""" + + ++ + + + + return '[%d bytes of binary content]' % len(content) ++ + + + """ +Returns True if a form should be shown for this method. +""" + + ++ + return # Cannot use form overloading ++ + + + view.check_object_permissions(request, obj) + + + ++ + + + + + + + + + #if getattr(v, 'queryset', None): +# kwargs['queryset'] = v.queryset ++ + + + + kwargs['regex'] = v.regex ++ + + + + + kwargs['initial'] = v.default ++ + + + + + + + + + + + # We need to impersonate a request with the correct method, +# so that eg. any dynamic get_serializer_class methods return the +# correct form for each method. + + + + + +finally: + ++ + # We need to impersonate a request with the correct method, +# so that eg. any dynamic get_serializer_class methods return the +# correct form for each method. + + + + + +finally: + ++ + """ +Get a form, possibly bound to either the input or output data. +In the absence on of the Resource having an associated form then +provide a form that can be used to submit arbitrary content. +""" + + + ++ + + + + + + + + + # Creating an on the fly form see: +# http://stackoverflow.com/questions/3915024/dynamically-creating-classes-python + + + + ++ + """ +Returns a form that allows for arbitrary content types to be tunneled +via standard HTML forms. +(Which are typically application/x-www-form-urlencoded) +""" ++ # If we're not using content overloading there's no point in supplying a generic form, +# as the view won't treat the form's value as the content of the request. + +and api_settings.FORM_CONTENTTYPE_OVERRIDE): +return None ++ # Check permissions + + + ++ + + + + + # NB. http://jacobian.org/writing/dynamic-form-generation/ + + + ++ + label='Media type', +choices=choices, +initial=initial +) + +label='Content', +widget=forms.Textarea +) ++ + + + + + + + + + + + + """ +Render the HTML for the browsable API representation. +""" + + ++ + + + + + + + + + + + + + + + + + + + + + + + + + 'content': content, +'view': view, +'request': request, +'response': response, +'description': description, +'name': name, +'version': VERSION, +'breadcrumblist': breadcrumb_list, +'allowed_methods': view.allowed_methods, +'available_formats': [renderer.format for renderer in view.renderer_classes], ++ 'put_form': put_form, +'post_form': post_form, +'patch_form': patch_form, +'delete_form': delete_form, +'options_form': options_form, ++ 'raw_data_put_form': raw_data_put_form, +'raw_data_post_form': raw_data_post_form, +'raw_data_patch_form': raw_data_patch_form, +'raw_data_put_or_patch_form': raw_data_put_or_patch_form, ++ 'api_settings': api_settings +}) ++ + + # Munge DELETE Response code to allow us to return content +# (Do this *after* we've rendered the template so that we include +# the normal deletion response code in the output) + +response.status_code = status.HTTP_200_OK ++ + + |
+