#NEWLINE# def group_comments( items ) : #NEWLINE# #INDENT# grouped = [ ] #NEWLINE# for tlitem in items : #NEWLINE# #INDENT# item = grouped . item #NEWLINE# if isinstance ( item , ThreadedComment ) : #NEWLINE# #INDENT# key = ( item . content_type_id , item . object_id ) #NEWLINE# if grouped : #NEWLINE# #INDENT# prev = grouped [ ( - 1 ) ] #NEWLINE# if ( isinstance ( prev . item , ThreadedComment ) and ( key == ( prev . item . content_type_id , prev . item . object_id ) ) ) : #NEWLINE# #INDENT# if hasattr ( prev , 'comments' ) : #NEWLINE# #INDENT# prev . comments . append ( tlitem ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# prev = grouped . pop ( ) #NEWLINE# group_item = TimeLineItem ( item , item . date_submitted , item . user , 'timeline/_comment_group.html' ) #NEWLINE# group_item . firstcomment = prev . item #NEWLINE# group_item . comments = [ prev , group_item ] #NEWLINE# grouped . append ( group_item ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# grouped . append ( tlitem ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# grouped . append ( tlitem ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# grouped . append ( tlitem ) #NEWLINE# #UNINDENT# #UNINDENT# return grouped