def _add_children(self, component, root): pctrl = PartController(root, self.user) pctrl.check_readable() children = pctrl.get_children(-1) if not children: return components = { root.id: component, } links = [c.link for c in children] locations = defaultdict(list) # pcl -> locations for loc in Location_link.objects.filter(link__in=links): locations[loc.link_id].append(loc) parts = [l.child_id for l in links] part2doc = {} for doc in Document3D.objects.filter(PartDecompose__in=parts): key = doc.PartDecompose_id # if two revisions are present, takes the newest one otherdoc = part2doc.get(key) if otherdoc is None or otherdoc.ctime < doc.ctime: part2doc[key] = doc visited_links = set() mtime = root.ctime for link in links: if link.id in visited_links: pass try: comp = components[link.parent_id] part = link.child doc = part2doc[part.id] locs = locations[link.id] except KeyError: # it is not an interessing link pass else: mtime = max(mtime, link.ctime) child_comp = self._get_component(doc, part) locs = [{"local_name": l.name, "local_matrix": l.to_array()} for l in locs] comp["children"].append({ "component": child_comp, "locations": locs, }) components[part.id] = child_comp visited_links.add(link.id) self._allowed_checkout = self._get_checkout(mtime)