Hi Josh, 

Yes maybe it could be done with plain old CSS...I'll have a think.

In the meantime I wrote the following filter:

@register.filter(name='comment_level')                                          
    

  def 
comment_level(comment):                                                         

      
'''                                                                             

      Takes a comment and returns its level in the tree.                    
      Parent comments are not replies to anything and have level 
0.                   
      
'''                                                                             

      level = 
0                                                                       
      while 
True:                                                                     
          if not 
comment.replied_to:                                                  
              # comment is not a reply, but a level 0 
parent.                         
              
break                                                                   
          
else:                                                                       
              # comment is a reply, inc level 
+1                                      
              level += 
1                                                              
              # move to comment 
above                                                 
              comment = 
comment.replied_to                                            
          # at end of recursion, return the 
level                                          
      return level             

So now in my template I can get the comment level in the tree with {{ 
comment|comment_level}}....not sure if this function is particularly 
efficient, or if there is a much simpler way though. Maybe it will be 
useful for something else later....

I also realised I could test if a given comment had any children with 

      {% if comment.id in all_comments|defaultdict_keys %} 

(I had to use the filter `defaultdict_keys` that just returns 
`all_comments.keys()` instead of just calling .keys as normal, since this 
is a defaultdict not a dict. The problem is django tries 
all_comments['keys'] first when .keys is called on a dict in a template, 
and this being a defaultdict(list) is obliges with [] giving an empty list 
for the keys even when dict is full)
         


-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to