Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 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 = {} #we have to have boolItems
  15. new_item['title'] = title
  16. new_item['key'] = key
  17. new_item['children'] = children
  18. new_item['hideCheckbox'] = False
  19. new_item['selected'] = key in selected
  20. new_item['isFolder'] = bool(children)
  21. new_item['hideCheckbox'] = bool(children) and leafsOnly
  22. new_item['expand'] = key in selected or isSomethingSelectedInChildren(children, selected)
  23. retval.append(new_item)
  24. return retval
  25.  
  26.  
  27. def isSomethingSelectedInChildren(children, selected):
  28. return bool(set(children.keys()).intersection(selected)) \
  29. or bool([_ for _ in children
  30. if children[_].children and isSomethingSelectedInChildren(children[_].children, selected)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement