def render_pattern(request, template_name, allow_non_patterns=False): if not allow_non_patterns and not is_pattern(template_name): raise TemplateIsNotPattern context = get_pattern_context(template_name) context[get_pattern_context_var_name()] = True return render_to_string(template_name, request=request, context=context)
def render_pattern(request, template_name, allow_non_patterns=False, config=None): if not allow_non_patterns and not is_pattern(template_name): raise TemplateIsNotPattern if not config: config = get_pattern_config(template_name) context = config.get("context", {}) tags = config.get("tags", {}) mark_context_strings_safe(context) context[get_pattern_context_var_name()] = True context["__pattern_library_tag_overrides"] = tags for modifier in registry.get_for_template(template_name): modifier(context=context, request=request) return render_to_string(template_name, request=request, context=context)
def is_pattern_library_context(context): context_var_name = get_pattern_context_var_name() return context.get(context_var_name) is True