def render_to_string(template_name, dictionary, context=None, namespace='main'): # see if there is an override template defined in the microsite template_name = MicrositeConfiguration.get_microsite_template_path(template_name) context_instance = Context(dictionary) # add dictionary to context_instance context_instance.update(dictionary or {}) # collapse context_instance to a single dictionary for mako context_dictionary = {} context_instance['settings'] = settings context_instance['EDX_ROOT_URL'] = settings.EDX_ROOT_URL context_instance['marketing_link'] = marketing_link # In various testing contexts, there might not be a current request context. if edxmako.middleware.requestcontext is not None: for d in edxmako.middleware.requestcontext: context_dictionary.update(d) for d in context_instance: context_dictionary.update(d) if context: context_dictionary.update(context) # fetch and render template template = edxmako.lookup[namespace].get_template(template_name) return template.render_unicode(**context_dictionary)
def render_to_string(template_name, dictionary, context=None, namespace='main'): # see if there is an override template defined in the microsite template_name = MicrositeConfiguration.get_microsite_template_path( template_name) context_instance = Context(dictionary) # add dictionary to context_instance context_instance.update(dictionary or {}) # collapse context_instance to a single dictionary for mako context_dictionary = {} context_instance['settings'] = settings context_instance['EDX_ROOT_URL'] = settings.EDX_ROOT_URL context_instance['marketing_link'] = marketing_link # In various testing contexts, there might not be a current request context. if edxmako.middleware.requestcontext is not None: for d in edxmako.middleware.requestcontext: context_dictionary.update(d) for d in context_instance: context_dictionary.update(d) if context: context_dictionary.update(context) # fetch and render template template = lookup_template(namespace, template_name) return template.render_unicode(**context_dictionary)
def render_to_response(template_name, dictionary=None, context_instance=None, namespace='main', **kwargs): """ Returns a HttpResponse whose content is filled with the result of calling lookup.get_template(args[0]).render with the passed arguments. """ # see if there is an override template defined in the microsite template_name = MicrositeConfiguration.get_microsite_template_path(template_name) dictionary = dictionary or {} return HttpResponse(render_to_string(template_name, dictionary, context_instance, namespace), **kwargs)
def render_to_response(template_name, dictionary=None, context_instance=None, namespace='main', **kwargs): """ Returns a HttpResponse whose content is filled with the result of calling lookup.get_template(args[0]).render with the passed arguments. """ # see if there is an override template defined in the microsite template_name = MicrositeConfiguration.get_microsite_template_path( template_name) dictionary = dictionary or {} return HttpResponse( render_to_string(template_name, dictionary, context_instance, namespace), **kwargs)