예제 #1
0
 def test_view(self):
     client = Client()
     url = reverse("viewlet", args=["hello_cache"])
     response = client.get(url, {"name": u"wörld"})
     self.assertEqual(response.status_code, 200)
     html = viewlet.call("hello_cache", None, u"wörld")
     self.assertEqual(response.content.decode("utf-8"), html)
예제 #2
0
 def test_view(self):
     client = Client()
     url = reverse('viewlet', args=['hello_cache'])
     response = client.get(url, {'name': u'wörld'})
     self.assertEqual(response.status_code, 200)
     html = viewlet.call('hello_cache', None, u'wörld')
     self.assertEqual(response.content.decode('utf-8'), html)
예제 #3
0
 def test_view(self):
     client = Client()
     url = reverse('viewlet', args=['hello_cache'])
     response = client.get(url, {'name': u'wörld'})
     self.assertEqual(response.status_code, 200)
     html = viewlet.call('hello_cache', None, u'wörld')
     self.assertEqual(response.content.decode('utf-8'), html)
예제 #4
0
 def render(self, context):
     try:
         args = [arg.resolve(context) for arg in self.viewlet_args]
         kwargs = dict((key, value.resolve(context)) for key, value in six.iteritems(self.viewlet_kwargs))
         template = viewlet.call(self.viewlet_name, context, *args, **kwargs)
         return mark_safe(template)
     except UnknownViewlet as e:
         logger.exception(e)
         raise
예제 #5
0
def viewlet_view(request, name):
    context = {"request": request}
    kwargs = {"request": request}

    # This feels klunky, is there a better way to do it?
    kwargs.update({k: ",".join(request.GET.getlist(k)) for k in request.GET})

    output = viewlet.call(name, context, **kwargs)
    resp = HttpResponse(output)
    resp["X-Robots-Tag"] = "noindex"
    return resp
예제 #6
0
def viewlet_view(request, name):
    if django.VERSION >= (1, 8):
        context = {}
        kwargs = {'request': request}
    else:
        context = RequestContext(request)
        kwargs = {}

    kwargs.update(querydict_to_kwargs(request.GET))
    output = viewlet.call(name, context, **kwargs)
    return HttpResponse(output)
예제 #7
0
 def _call_viewlet(self, name, context, viewlet_args, caller=None):
     context = context.get_all()
     return mark_safe(viewlet.call(name, context, *viewlet_args))
예제 #8
0
 def test_unicode_cache(self):
     html1 = viewlet.call('hello_cache', None, u'wörld')
     sleep(0.01)
     html2 = viewlet.call('hello_cache', None, u'wörld')
     self.assertEquals(html1, html2)
예제 #9
0
 def _call_viewlet(self, name, context, viewlet_args, caller=None):
     context = context.get_all()
     return mark_safe(viewlet.call(name, context, *viewlet_args))
예제 #10
0
 def test_unicode_cache(self):
     html1 = viewlet.call('hello_cache', None, u'wörld')
     sleep(0.01)
     html2 = viewlet.call('hello_cache', None, u'wörld')
     self.assertEquals(html1, html2)
예제 #11
0
def viewlet_view(request, name):
    context = RequestContext(request)
    kwargs = querydict_to_kwargs(request.GET)
    output = viewlet.call(name, context, **kwargs)
    return HttpResponse(output)
예제 #12
0
 def test_view(self):
     request = DummyRequest()
     request.GET['name'] = ('world',)
     response = viewlet_view(request, 'hello_cache')
     html = viewlet.call('hello_cache', None, 'world')
     self.assertEqual(response.content, html)
예제 #13
0
 def render(self, context):
     try:
         args = [arg.resolve(context) for arg in self.viewlet_args]
         return viewlet.call(self.viewlet_name, context, *args)
     except ViewletException as e:
         logger.exception(e)
예제 #14
0
 def test_unicode_cache(self):
     html1 = viewlet.call("hello_cache", None, u"wörld")
     sleep(0.01)
     html2 = viewlet.call("hello_cache", None, u"wörld")
     self.assertEquals(html1, html2)