fork download
  1. # your code goes here
  2. def commentsAll(request):
  3. c = {}
  4. c.update(csrf(request))
  5. link_all = Link.objects.all()
  6. filter_descendant = list(Link.objects.values('descendant'))
  7. #print filter_descendant
  8. list_sortig_ancestor = []
  9. for item in link_all:
  10. if item.ancestor not in list_sortig_ancestor:
  11. list_sortig_ancestor.append(item.ancestor)
  12. #делаем копию, в которую будем складывать всё
  13. list_comment_id = list_sortig_ancestor[:]
  14. #print list_sortig_ancestor
  15. new_link_all = []
  16. for item in link_all:
  17. new_link_all.append('{0}'.format(item.ancestor))
  18.  
  19. #делаем из строк числа для того чтобы потом узнать сколько раз число входит
  20. number_list_ancestor = []
  21. for item in new_link_all:
  22. if item == 'None':
  23. break
  24. else: number_list_ancestor.append(int(item))
  25. list_item_descendant_for = []
  26. clearx = []
  27. for itemsort in list_sortig_ancestor:
  28. length_descendand = number_list_ancestor.count(itemsort) #узнали длину cсколько раз входит
  29. #print u'сколько раз предок', length_descendand
  30. for itemlink in link_all:
  31. if (itemlink.ancestor == itemsort):
  32. list_item_descendant_for.append(itemlink.descendant) #добивили в массив потомков
  33. #print itemlink.descendant
  34. #print 'list_item_descendant_for', list_item_descendant_for
  35. if (length_descendand == len(list_item_descendant_for)): #если длины массивов помоквов и количество эл. в линкалл совпадет
  36. #print u'равно'
  37. i = list_comment_id.index(itemsort)
  38. i = i + 1
  39. list_comment_id.insert(i, list_item_descendant_for) #list_comment_id[i:i] = list_item_descendant_for
  40. list_item_descendant_for = clearx[:]
  41. elif itemlink.ancestor is not itemsort:
  42. continue
  43.  
  44. #print list_sortig_ancestor
  45. print list_comment_id
  46.  
  47. new_list_comment = []
  48. for item in list_sortig_ancestor:
  49. if item not in new_list_comment:
  50. new_list_comment.append(item)
  51. for i in link_all:
  52. if i.ancestor == item:
  53. if i.descendant not in new_list_comment:
  54. index = new_list_comment.index(item)
  55. index = index + 1
  56. new_list_comment.insert(index, i.descendant)
  57.  
  58.  
  59.  
  60. while new_list_comment.count(None) != 0:
  61. new_list_comment.remove(None)
  62.  
  63.  
  64.  
  65. list_link_all = []
  66. for i in link_all:
  67. if i.descendant == None:
  68. i.descendant = 0
  69. new = [i.ancestor,i.descendant]
  70. list(new)
  71. list_link_all.append(new)
  72.  
  73. #print list_link_all
  74. print new_list_comment
  75.  
  76.  
  77. all_comments = Comments.objects.all()
  78.  
  79. v = RequestContext(request, {'all_comments': all_comments, 'new_list_comment': new_list_comment, 'list_link_all': list_link_all })
  80. return render_to_response('comments_all.html', v)
Success #stdin #stdout 0.02s 9016KB
stdin
Standard input is empty
stdout
Standard output is empty