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
def convert_docs_to_html(self, docs): """ Convert the given docs to to html. Defaults to formatting the docs using markdown, but you can override this method if you want something else. """ return apply_markdown(docs)
def test_markdown(self): """Ensure markdown to HTML works as expected""" if apply_markdown: self.assertEquals(apply_markdown(DESCRIPTION), MARKED_DOWN)
def markup_description(self, description): if apply_markdown: description = apply_markdown(description) else: description = escape(description).replace('\n', '<br />') return mark_safe(description)
def test_markdown(self): """Ensure markdown to HTML works as expected""" if apply_markdown: gte_21_match = apply_markdown(DESCRIPTION) == MARKED_DOWN_gte_21 lt_21_match = apply_markdown(DESCRIPTION) == MARKED_DOWN_lt_21 self.assertTrue(gte_21_match or lt_21_match)