Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. def dict2dynatree(input_dict, selected, leafsOnly):
  2. """
  3. Recursively parse the dictionary as we get it from the
  4. IVocabulary, and transform it to a a dictionary as needed for
  5. dynatree
  6. """
  7. if input_dict is None:
  8. return None
  9. retval = []
  10. for key in input_dict:
  11. title, children = input_dict[key]
  12. children = dict2dynatree(children, selected, leafsOnly)
  13.  
  14. new_item = {}
  15. new_item['title'] = title
  16. new_item['key'] = key
  17. new_item['children'] = children
  18. new_item['hideCheckbox'] = False
  19. if key in selected:
  20. new_item['select'] = True
  21. if children:
  22. new_item['isFolder'] = True
  23. if children and leafsOnly:
  24. new_item['hideCheckbox'] = True
  25. if key in selected:
  26. new_item['expand'] = True
  27.  
  28. new_item['expand'] = key in selected or isSomethingSelectedInChildren(children, selected)
  29.  
  30. retval.append(new_item)
  31. return retval
  32.  
  33.  
  34. def isSomethingSelectedInChildren(children, selected):
  35. import pdb; pdb.set_trace()
  36. return bool(set(children.keys()).intersection(selected)) \
  37. or bool([_ for _ in children
  38. if children[_].children and isSomethingSelectedInChildren(children[_].children, selected)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement