Beispiel #1
0
    def test_accepts_html(self):
        self.assertTrue(accepts_html('text/html'))
        self.assertTrue(accepts_html('text/*'))
        self.assertTrue(accepts_html('*/*'))
        self.assertTrue(accepts_html('audio/*, text/plain, text/*'))
        self.assertTrue(accepts_html(
                'text/*;q=0.3, text/html;q=0.7, text/html;level=1, ' +
                'text/html;level=2;q=0.4, */*;q=0.5'))

        self.assertFalse(accepts_html('text/plain'))
        self.assertFalse(accepts_html('audio/*'))
        self.assertFalse(accepts_html('text/x-dvi; q=0.8, text/x-c'))
        self.assertFalse(accepts_html(None))
Beispiel #2
0
    def test_accepts_html(self):
        self.assertTrue(accepts_html('text/html'))
        self.assertTrue(accepts_html('text/*'))
        self.assertTrue(accepts_html('*/*'))
        self.assertTrue(accepts_html('audio/*, text/plain, text/*'))
        self.assertTrue(
            accepts_html('text/*;q=0.3, text/html;q=0.7, text/html;level=1, ' +
                         'text/html;level=2;q=0.4, */*;q=0.5'))

        self.assertFalse(accepts_html('text/plain'))
        self.assertFalse(accepts_html('audio/*'))
        self.assertFalse(accepts_html('text/x-dvi; q=0.8, text/x-c'))
        self.assertFalse(accepts_html(None))
Beispiel #3
0
def _html_or_none(request, template, context={}):
    """Renders html response string from a given template.

    Returns None if request does not accept html response type.
    """
    if (http.accepts_html(request.META.get('HTTP_ACCEPT'))):
        return render_to_string(template, context)
    return None
Beispiel #4
0
def _html_or_none(request, template, context={}):
    """Renders html response string from a given template.

    Returns None if request does not accept html response type.
    """
    if (http.accepts_html(request.META.get('HTTP_ACCEPT'))):
        return render_to_string(template, context)
    return None