def render(self, context=None, request=None): # type: (Optional[Union[Dict[str, Any], Context]], Optional[HttpRequest]) -> text_type if context is None: context = {} if isinstance(context, Context): # Jinja2 expects a dictionary # This condition makes sure that `flatten` is called only when # `context` is an instance of `Context`. # # Note: If we don't ignore then mypy complains about missing # `flatten` attribute in some members of union. context = context.flatten() # type: ignore if request is not None: context['request'] = request context['csrf_input'] = csrf_input_lazy(request) context['csrf_token'] = csrf_token_lazy(request) for context_processor in self.context_processors: cp = import_string(context_processor) context.update(cp(request)) if self.debug: template_rendered.send(sender=self, template=self, context=context) return self.template.render(context)
def instrumented_test_render(self, context): """ An instrumented Template render method, providing a signal that can be intercepted by the test system Client """ template_rendered.send(sender=self, template=self, context=context) return self.nodelist.render(context)
def instrumented_render(template_object, *args, **kwargs): context = dict(*args, **kwargs) template_rendered.send(sender=template_object, template=template_object, context=context) return Jinja2Template._original_render(template_object, *args, **kwargs)
def render_to_response(self, data, response, jsoncallback=None, *args, **kwargs): # for successfull testing with django test client plain_data = deepcopy(data) if type(data) == dict: for key in data: if isinstance(data[key], QuerySet) \ or (isinstance(data[key], list) and len(data[key]) != 0 and isinstance(data[key][0], models.Model)): data[key] = self.serialize_qs(data[key], *args, **kwargs) else: data = self.serialize_qs(data, *args, **kwargs) if 'extras' in kwargs: del kwargs['extras'] if 'relations' in kwargs: del kwargs['relations'] if settings.DEBUG: kwargs['indent'] = 4 response.content = simplejson.dumps(data, cls=DjangoJSONEncoder, *args, **kwargs) template_rendered.send(sender=self, template=self, context={'data':plain_data, 'sdata': data}) if self.format == 'json': response['Content-Type'] = 'application/x-javascript; charset=utf-8' if jsoncallback: response.content = ''.join([jsoncallback, '(', force_unicode(response.content), ')']) return response
def render(self, context=None, request=None): # type: (Optional[Union[Dict[str, Any], Context]], Optional[HttpRequest]) -> text_type if context is None: context = {} if isinstance(context, Context): # Jinja2 expects a dictionary # This condition makes sure that `flatten` is called only when # `context` is an instance of `Context`. # # Note: If we don't ignore then mypy complains about missing # `flatten` attribute in some members of union. context = context.flatten() # type: ignore if request is not None: context['request'] = request context['csrf_input'] = csrf_input_lazy(request) context['csrf_token'] = csrf_token_lazy(request) for context_processor in self.context_processors: cp = import_string(context_processor) context.update(cp(request)) if self.debug: template_rendered.send(sender=self, template=self, context=context) return self.template.render(context)
def instrumented_test_render(self, context): """ An instrumented Template render method, providing a signal that can be intercepted by the test system Client """ template_rendered.send(sender=self, template=self, context=context) return self.nodelist.render(context)
def render(self, context=None): """Differs from Django's own render() slightly in that makes the ``context`` parameter optional. We try to strike a middle ground here between implementing Django's interface while still supporting Jinja's own call syntax as well. """ self.origin = Origin(self.filename) template_rendered.send(sender=self, template=self, context=context) if context is None: context = {} else: context = dict_from_django_context(context) assert isinstance(context, dict) # Required for **-operator. template = super(Template, self).render(**context) return template
def render_to_response(self, data, response, jsoncallback=None, *args, **kwargs): # for successfull testing with django test client plain_data = deepcopy(data) if type(data) == dict: for key in data: if isinstance(data[key], QuerySet) \ or (isinstance(data[key], list) and len(data[key]) != 0 and isinstance(data[key][0], models.Model)): data[key] = self.serialize_qs(data[key], *args, **kwargs) else: data = self.serialize_qs(data, *args, **kwargs) if 'extras' in kwargs: del kwargs['extras'] if 'relations' in kwargs: del kwargs['relations'] if settings.DEBUG: kwargs['indent'] = 4 response.content = simplejson.dumps(data, cls=DjangoJSONEncoder, *args, **kwargs) template_rendered.send(sender=self, template=self, context={ 'data': plain_data, 'sdata': data }) if self.format == 'json': response[ 'Content-Type'] = 'application/x-javascript; charset=utf-8' if jsoncallback: response.content = ''.join( [jsoncallback, '(', force_unicode(response.content), ')']) return response
def render(self, context=None, request=None): if context is None: context = {} if isinstance(context, Context): context = context.flatten() # Jinja2 expects a dictionary if request is not None: context['request'] = request context['csrf_input'] = csrf_input_lazy(request) context['csrf_token'] = csrf_token_lazy(request) for context_processor in self.context_processors: cp = import_string(context_processor) context.update(cp(request)) if self.debug: template_rendered.send(sender=self, template=self, context=context) return self.template.render(context)
def render(self, context=None, request=None): # type: (Optional[Union[Dict[str, Any], Context]], Optional[HttpRequest]) -> Text if context is None: context = {} if isinstance(context, Context): # Jinja2 expects a dictionary # This condition makes sure that `flatten` is called only when # `context` is an instance of `Context`. # # Note: If we don't ignore then mypy complains about missing # `flatten` attribute in some members of union. context = context.flatten() # type: ignore result = super(Template, self).render(context=context, request=request) if self.backend.debug: template_rendered.send(sender=self, template=self, context=context) return result
def rendered_content(self): """Return the freshly rendered content for the template and context described by this JinjaTemplateResponse object.""" # first, get us the template object template = self.resolve_template(self.template_name) # sanity check: if this is a **Django** template object, then I just want # to go through superclass' system if isinstance(template, DjangoTemplate): context = super(JinjaTemplateResponse, self).resolve_context(self.context_data) else: context = self.resolve_context(self.context_data) # sanity check: are we in test mode? if self._in_test_mode: template_rendered.send(sender=self, template=self, context=context) # now render the template and return the content content = template.render(context) return content
def render(self, context): template_rendered.send( sender=self, template=self, context=context) return r(self, context)
def mako_callable_(context, *args, **kwargs): template_rendered.send(sender=self, template=self, context=context) return self.original_callable_[-1](context, *args, **kwargs)
import logging
def instrumented_render(template_object, *args, **kwargs): context = dict(*args, **kwargs) template_rendered.send(sender=template_object, template=template_object, context=context) return Jinja2Template._original_render(template_object, *args, **kwargs)
def render(self, context=None): template_rendered.send(sender=self, template=self, context=context) return func(self, context)
def mako_callable_(context, *args, **kwargs): template_rendered.send(sender=self, template=self, context=context) return self.original_callable_[-1](context, *args, **kwargs)