Ticket #6237: django-picking-simplenode.patch

File django-picking-simplenode.patch, 1.7 KB (added by Simon Law <simon@…>, 17 years ago)
  • django/template/__init__.py

    # HG changeset patch
    # User Simon Law <simon@akoha.org>
    # Date 1197999869 18000
    # Branch trunk
    # Node ID a742eea27d06087ce019c4564967bd3883b91c4c
    # Parent  6636f16ed3195d7021d339598a3b229e5ae6553e
    Allow pickling of django.template.SimpleNode objects.
    
    diff --git a/django/template/__init__.py b/django/template/__init__.py
    a b def generic_tag_compiler(params, default  
    890890        raise TemplateSyntaxError, message
    891891    return node_class(bits)
    892892
     893class SimpleNode(Node):
     894    def __init__(self, vars_to_resolve, func):
     895        self.vars_to_resolve = map(Variable, vars_to_resolve)
     896        self.func = func
     897
     898    def render(self, context):
     899        resolved_vars = [var.resolve(context) for var in self.vars_to_resolve]
     900        return self.func(*resolved_vars)
     901
    893902class Library(object):
    894903    def __init__(self):
    895904        self.filters = {}
    class Library(object):  
    946955    def simple_tag(self,func):
    947956        params, xx, xxx, defaults = getargspec(func)
    948957
    949         class SimpleNode(Node):
    950             def __init__(self, vars_to_resolve):
    951                 self.vars_to_resolve = map(Variable, vars_to_resolve)
    952 
    953             def render(self, context):
    954                 resolved_vars = [var.resolve(context) for var in self.vars_to_resolve]
    955                 return func(*resolved_vars)
     958        def SimpleNode__init__(self, vars_to_resolve):
     959            self.vars_to_resolve = map(Variable, vars_to_resolve)
     960            self.func = func
     961        SimpleNode.__init__ = SimpleNode__init__
    956962
    957963        compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, SimpleNode)
    958964        compile_func.__doc__ = func.__doc__
Back to Top