Пример #1
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
Пример #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 = 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
Пример #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,
                '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
Пример #5
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.
        """

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

        try:
            template = loader.get_template("%d.html" % self.view.response.status)
        except:
            template = None

        if template:
            content = self._get_content(self.view, self.view.request, obj, media_type)
            context = RequestContext(self.view.request, {"content": content})
            ret = template.render(context)
            return ret

        template = loader.get_template(self.template)
        context = RequestContext(self.view.request, {
            'content': obj,
            'view': self.view,
            'response': self.view.response,
            'available_formats': self.view._rendered_formats,
            'login_url': login_url,
            # A hook here. a convenience way to add extra context
            'extra': getattr(self.view, 'extra', None),
            '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