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)
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)
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
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
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)
def _call_viewlet(self, name, context, viewlet_args, caller=None): context = context.get_all() return mark_safe(viewlet.call(name, context, *viewlet_args))
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)
def viewlet_view(request, name): context = RequestContext(request) kwargs = querydict_to_kwargs(request.GET) output = viewlet.call(name, context, **kwargs) return HttpResponse(output)
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)
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)
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)