Exemplo n.º 1
0
 def test_nested_resource_instance_breadcrumbs(self):
     url = '/resource/123/abc'
     self.assertEqual(get_breadcrumbs(url), [('Root', '/'),
                                         ('Resource Root', '/resource/'),
                                         ('Resource Instance', '/resource/123'),
                                         ('Nested Resource Root', '/resource/123/'),
                                         ('Nested Resource Instance', '/resource/123/abc')])
Exemplo n.º 2
0
    def render(self, obj=None, media_type=None):
        """
        Renders *obj* using the :attr:`template` set on the class.

        The context used in the template contains all the information
        needed to self-document the response to this request.
        """
        content = self._get_content(self.view, self.view.request, obj, media_type)

        put_form_instance = self._get_form_instance(self.view, 'put')
        post_form_instance = self._get_form_instance(self.view, 'post')

        if url_resolves(settings.LOGIN_URL) and url_resolves(settings.LOGOUT_URL):
            login_url = "%s?next=%s" % (settings.LOGIN_URL, quote_plus(self.view.request.path))
            logout_url = "%s?next=%s" % (settings.LOGOUT_URL, quote_plus(self.view.request.path))
        else:
            login_url = None
            logout_url = None

        name = get_name(self.view)
        description = get_description(self.view)

        markeddown = None
        if apply_markdown:
            try:
                markeddown = apply_markdown(description)
            except AttributeError:
                markeddown = None

        breadcrumb_list = get_breadcrumbs(self.view.request.path)

        template = loader.get_template(self.template)
        context = RequestContext(self.view.request, {
            'content': content,
            'view': self.view,
            'request': self.view.request, # TODO: remove
            'response': self.view.response,
            'description': description,
            'name': name,
            'markeddown': markeddown,
            'breadcrumblist': breadcrumb_list,
            'available_media_types': self.view._rendered_media_types,
            'put_form': put_form_instance,
            'post_form': post_form_instance,
            'login_url': login_url,
            'logout_url': logout_url,
            'ACCEPT_PARAM': getattr(self.view, '_ACCEPT_QUERY_PARAM', None),
            'METHOD_PARAM': getattr(self.view, '_METHOD_PARAM', None),
            'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX
        })
        
        ret = template.render(context)

        # 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)
        if self.view.response.status == 204:
            self.view.response.status = 200

        return ret
Exemplo n.º 3
0
    def render(self, obj=None, media_type=None):
        """
        Renders *obj* using the :attr:`template` set on the class.

        The context used in the template contains all the information
        needed to self-document the response to this request.
        """

        content = self._get_content(self.view, self.view.request, obj, media_type)

        put_form_instance = self._get_form_instance(self.view, "put")
        post_form_instance = self._get_form_instance(self.view, "post")

        if url_resolves(settings.LOGIN_URL) and url_resolves(settings.LOGOUT_URL):
            login_url = "%s?next=%s" % (settings.LOGIN_URL, quote_plus(self.view.request.path))
            logout_url = "%s?next=%s" % (settings.LOGOUT_URL, quote_plus(self.view.request.path))
        else:
            login_url = None
            logout_url = None

        name = self.get_name()
        description = self.get_description()

        breadcrumb_list = get_breadcrumbs(self.view.request.path)

        template = loader.get_template(self.template)
        context = RequestContext(
            self.view.request,
            {
                "content": content,
                "view": self.view,
                "request": self.view.request,  # TODO: remove
                "response": self.view.response,
                "description": description,
                "name": name,
                "version": VERSION,
                "breadcrumblist": breadcrumb_list,
                "available_formats": self.view._rendered_formats,
                "put_form": put_form_instance,
                "post_form": post_form_instance,
                "login_url": login_url,
                "logout_url": logout_url,
                "FORMAT_PARAM": self._FORMAT_QUERY_PARAM,
                "METHOD_PARAM": getattr(self.view, "_METHOD_PARAM", None),
                "ADMIN_MEDIA_PREFIX": getattr(settings, "ADMIN_MEDIA_PREFIX", None),
            },
        )

        ret = template.render(context)

        # 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)
        if self.view.response.status == 204:
            self.view.response.status = 200

        return ret
Exemplo n.º 4
0
    def render(self, obj=None, media_type=None):
        """
        Renders *obj* using the :attr:`template` set on the class.

        The context used in the template contains all the information
        needed to self-document the response to this request.
        """

        content = self._get_content(self.view, self.view.request, obj,
                                    media_type)

        put_form_instance = self._get_form_instance(self.view, 'put')
        post_form_instance = self._get_form_instance(self.view, 'post')

        if url_resolves(settings.LOGIN_URL) and url_resolves(
                settings.LOGOUT_URL):
            login_url = "%s?next=%s" % (settings.LOGIN_URL,
                                        quote_plus(self.view.request.path))
            logout_url = "%s?next=%s" % (settings.LOGOUT_URL,
                                         quote_plus(self.view.request.path))
        else:
            login_url = None
            logout_url = None

        name = self.get_name()
        description = self.get_description()

        breadcrumb_list = get_breadcrumbs(self.view.request.path)

        template = loader.get_template(self.template)
        context = RequestContext(
            self.view.request, {
                'content': content,
                'view': self.view,
                'request': self.view.request,
                'response': self.view.response,
                'description': description,
                'name': name,
                'version': VERSION,
                'breadcrumblist': breadcrumb_list,
                'available_formats': self.view._rendered_formats,
                'put_form': put_form_instance,
                'post_form': post_form_instance,
                'FORMAT_PARAM': self._FORMAT_QUERY_PARAM,
                'METHOD_PARAM': getattr(self.view, '_METHOD_PARAM', None),
            })

        ret = template.render(context)

        # 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)
        if self.view.response.status == 204:
            self.view.response.status = 200

        return ret
    def render(self, obj=None, media_type=None):
        """
        Renders *obj* using the :attr:`template` set on the class.

        The context used in the template contains all the information
        needed to self-document the response to this request.
        """

        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')
        post_form_instance = self._get_form_instance(self.view, 'post')

        if url_resolves(settings.LOGIN_URL) and url_resolves(settings.LOGOUT_URL):
            login_url = "%s?next=%s" % (settings.LOGIN_URL, quote_plus(self.view.request.path))
            logout_url = "%s?next=%s" % (settings.LOGOUT_URL, quote_plus(self.view.request.path))
        else:
            login_url = None
            logout_url = None

        name = self.get_name()
        description = self.get_description()

        breadcrumb_list = get_breadcrumbs(self.view.request.path)

        template = loader.get_template(self.template)
        context = RequestContext(self.view.request, {
            'content': content,
            'view': self.view,
            'request': self.view.request,
            'response': self.view.response,
            'description': description,
            'name': name,
            'version': VERSION,
            'breadcrumblist': breadcrumb_list,
            'available_formats': self.view._rendered_formats,
            'get_form': get_form_instance,
            'put_form': put_form_instance,
            'post_form': post_form_instance,
            'FORMAT_PARAM': self._FORMAT_QUERY_PARAM,
            'METHOD_PARAM': getattr(self.view, '_METHOD_PARAM', None),
        })

        ret = template.render(context)

        # 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)
        if self.view.response.status == 204:
            self.view.response.status = 200

        return ret
Exemplo n.º 6
0
 def test_broken_url_breadcrumbs_handled_gracefully(self):
     url = '/foobar'
     self.assertEqual(get_breadcrumbs(url), [('Root', '/')])
Exemplo n.º 7
0
 def test_resource_root_breadcrumbs(self):
     url = '/resource/'
     self.assertEqual(get_breadcrumbs(url), [('Root', '/'),
                                         ('Resource Root', '/resource/')])
Exemplo n.º 8
0
 def test_root_breadcrumbs(self):
     url = '/'
     self.assertEqual(get_breadcrumbs(url), [('Root', '/')])