Ejemplo n.º 1
0
    def render_pointer(self, context, handle_errors=True):
        vars_qs = self.variables.select_related('snippet_variable').all()

        def var_for_context(var):
            default, overwrite = var.formatted_value, None
            if allow_inheritance:
                overwrite = context.get(
                    inherit_variable_pattern.format(identifier=var.pk))
            name = var.snippet_variable.name
            value = overwrite if overwrite is not None else default
            return (name, value)

        variables = dict(var_for_context(var) for var in vars_qs)
        context.update(variables)
        sekizai_differ = sekizai_context_watcher(context)
        try:
            content = self.snippet.render(context)
        except VariableDoesNotExist as exc:
            logger.exception("Cannot render plugin %s!", self)
            if handle_errors:
                content = render_to_string("smartsnippets/unrenderable_smartsnippet.html",
                                           {'plugin_name': str(self)})
            else:
                raise UnrenderableSmarSnippet(exc)
        sekizai_diff = sekizai_differ.get_changes()
        user = context.get('request').user
        return self.set_and_get_cache(user, sekizai_diff, content)
Ejemplo n.º 2
0
 def render_pointer(self, context):
     vars_qs = self.variables.select_related('snippet_variable').all()
     variables = dict(
         (var.snippet_variable.name, var.formatted_value)
         for var in vars_qs
     )
     context.update(variables)
     sekizai_differ = sekizai_context_watcher(context)
     content = self.snippet.render(context)
     sekizai_diff = sekizai_differ.get_changes()
     user = context.get('request').user
     return self.set_and_get_cache(user, sekizai_diff, content)
    def render_pointer(self, context):
        vars_qs = self.variables.select_related('snippet_variable').all()

        def var_for_context(var):
            default, overwrite = var.formatted_value, None
            if allow_inheritance:
                overwrite = context.get(
                    inherit_variable_pattern.format(identifier=var.pk))
            name = var.snippet_variable.name
            value = overwrite if overwrite is not None else default
            return (name, value)

        variables = dict(var_for_context(var) for var in vars_qs)
        context.update(variables)
        sekizai_differ = sekizai_context_watcher(context)
        content = self.snippet.render(context)
        sekizai_diff = sekizai_differ.get_changes()
        user = context.get('request').user
        return self.set_and_get_cache(user, sekizai_diff, content)
Ejemplo n.º 4
0
    def render_pointer(self, context):
        vars_qs = self.variables.select_related('snippet_variable').all()

        def var_for_context(var):
            default, overwrite = var.formatted_value, None
            if allow_inheritance:
                overwrite = context.get(
                    inherit_variable_pattern.format(identifier=var.pk))
            name = var.snippet_variable.name
            value = overwrite if overwrite is not None else default
            return (name, value)

        variables = dict(var_for_context(var) for var in vars_qs)
        context.update(variables)
        sekizai_differ = sekizai_context_watcher(context)
        content = self.snippet.render(context)
        sekizai_diff = sekizai_differ.get_changes()
        user = context.get('request').user
        return self.set_and_get_cache(user, sekizai_diff, content)