Commits

Dmitri Lebedev  committed 3e76b94

integrated inline.py with django_partial_page

  • Participants
  • Parent commits 808be44

Comments (0)

Files changed (1)

File example/django_inline/templatetags/inline.py

 from django.template import Library, Node, TemplateSyntaxError, loader
 from django_inline import templates_list
 
+try:
+    from django_partial_page.middleware import capture_blocks
+except ImportError:
+    capture_blocks = lambda x: x
+
 register = Library()
 
+
+class EditableNode(Node):
+    def __init__(self, nodelist, obj, field):
+        self.nodelist = nodelist
+        self.obj = obj
+        self.field = field
+
+    @capture_blocks
+    def render(self, context):
+        import ipdb; ipdb.set_trace()
+        inner_content = self.nodelist.render(context)
+        obj = self.obj.resolve(context)
+        field_name = self.field.resolve(context)
+        class_name = obj.__class__.__name__
+        
+        self.name = editable_id(obj, field_name)
+        
+        if not context['user'].has_perm('%s.can_edit' % class_name, obj):
+            return inner_content
+        
+        return loader.render_to_string(templates_list('inline-editable.html', obj, field_name), {
+            'obj': obj,
+            'field_name': field_name,
+            'inner': inner_content,
+        })
+
+
 @register.tag
 def editable(parser, token):
     """
     return EditableNode(nodelist, *map(parser.compile_filter, bits[1:]))
 
 
-class EditableNode(Node):
-    def __init__(self, nodelist, obj, field):
-        self.nodelist = nodelist
-        self.obj = obj
-        self.field = field
-
-    def render(self, context):
-        inner_content = self.nodelist.render(context)
-        obj = self.obj.resolve(context)
-        field_name = self.field.resolve(context)
-        class_name = obj.__class__.__name__
-        if not context['user'].has_perm('%s.can_edit' % class_name, obj):
-            return inner_content
-        
-        return loader.render_to_string(templates_list('inline-editable.html', obj, field_name), {
-            'obj': obj,
-            'field_name': field_name,
-            'inner': inner_content,
-        })
-
-
 @register.simple_tag
 def editable_id(obj, field_name):
     class_name = obj.__class__.__name__