web/contentment/taxonomy.py
def _find_references(self, items, depth=0, finded_ids=None):
		"""
		Recursively finds all db references to be dereferenced

		:param items: The iterable (dict, list, queryset)
		:param depth: The current depth of recursion
		"""
		# if items and isinstance(items, list) and getattr(items[0], 'name', '') == 'child2':
		# 	import pudb; pudb.set_trace()
		reference_map = {}
		if not items or depth >= self.max_depth:
			return reference_map

		# Determine the iterator to use
		if not hasattr(items, 'items'):
			iterator = enumerate(items)
		else:
			iterator = iter(items.items())

		# Recursively find dbreferences
		depth += 1
		processed_ids = finded_ids if finded_ids is not None else set()
		for k, item in iterator:
			if isinstance(item, (Document, EmbeddedDocument)):
				for field_name, field in item._fields.items():
					v = item._data.get(field_name, None)
					if (v and getattr(field, 'document_type', object) is Taxonomy and
							isinstance(v, Taxonomy) and
							v.id not in processed_ids):
						processed_ids.add(v.id)
						reference_map.setdefault(type(v), set()).add(v.id)
					elif isinstance(v, DBRef) and v.id not in processed_ids:
						processed_ids.add(v.id)
						try:
							reference_map.setdefault(get_document(v.cls), set()).add(v.id)
						except AttributeError:
							reference_map.setdefault(field.document_type, set()).add(v.id)
					elif isinstance(v, (dict, SON)) and '_ref' in v and v['_ref'].id not in processed_ids:
						processed_ids.add(v['_ref'].id)
						reference_map.setdefault(get_document(v['_cls']), set()).add(v['_ref'].id)
					elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth:
						field_cls = getattr(getattr(field, 'field', None), 'document_type', None)
						references = self._find_references(v, depth, processed_ids)
						for key, refs in references.items():
							if isinstance(field_cls, (Document, TopLevelDocumentMetaclass)) and key is Taxonomy:
								key = field_cls
							reference_map.setdefault(key, set()).update(refs)
			elif isinstance(item, DBRef) and item.id not in processed_ids:
				processed_ids.add(item.id)
				reference_map.setdefault(item.collection, set()).add(item.id)
			elif isinstance(item, (dict, SON)) and '_ref' in item and item['_ref'].id not in processed_ids:
				processed_ids.add(item['_ref'].id)
				reference_map.setdefault(get_document(item['_cls']), set()).add(item['_ref'].id)
			elif isinstance(item, (dict, list, tuple)) and depth - 1 <= self.max_depth:
				references = self._find_references(item, depth - 1, processed_ids)
				for key, refs in references.items():
					reference_map.setdefault(key, set()).update(refs)

		return reference_map

		Recursively finds all db references to be dereferenced

		:param items: The iterable (dict, list, queryset)
		:param depth: The current depth of recursion
		
Recursively finds all db references to be dereferenced
Recursively finds all db references to be dereferenced
def _find_references(self, items, depth=0, finded_ids=None):
		reference_map = {}
		if not items or depth >= self.max_depth:
			return reference_map
		if not hasattr(items, 'items'):
			iterator = enumerate(items)
		else:
			iterator = iter(items.items())
		depth += 1
		processed_ids = finded_ids if finded_ids is not None else set()
		for k, item in iterator:
			if isinstance(item, (Document, EmbeddedDocument)):
				for field_name, field in item._fields.items():
					v = item._data.get(field_name, None)
					if (v and getattr(field, 'document_type', object) is Taxonomy and
							isinstance(v, Taxonomy) and
							v.id not in processed_ids):
						processed_ids.add(v.id)
						reference_map.setdefault(type(v), set()).add(v.id)
					elif isinstance(v, DBRef) and v.id not in processed_ids:
						processed_ids.add(v.id)
						try:
							reference_map.setdefault(get_document(v.cls), set()).add(v.id)
						except AttributeError:
							reference_map.setdefault(field.document_type, set()).add(v.id)
					elif isinstance(v, (dict, SON)) and '_ref' in v and v['_ref'].id not in processed_ids:
						processed_ids.add(v['_ref'].id)
						reference_map.setdefault(get_document(v['_cls']), set()).add(v['_ref'].id)
					elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth:
						field_cls = getattr(getattr(field, 'field', None), 'document_type', None)
						references = self._find_references(v, depth, processed_ids)
						for key, refs in references.items():
							if isinstance(field_cls, (Document, TopLevelDocumentMetaclass)) and key is Taxonomy:
								key = field_cls
							reference_map.setdefault(key, set()).update(refs)
			elif isinstance(item, DBRef) and item.id not in processed_ids:
				processed_ids.add(item.id)
				reference_map.setdefault(item.collection, set()).add(item.id)
			elif isinstance(item, (dict, SON)) and '_ref' in item and item['_ref'].id not in processed_ids:
				processed_ids.add(item['_ref'].id)
				reference_map.setdefault(get_document(item['_cls']), set()).add(item['_ref'].id)
			elif isinstance(item, (dict, list, tuple)) and depth - 1 <= self.max_depth:
				references = self._find_references(item, depth - 1, processed_ids)
				for key, refs in references.items():
					reference_map.setdefault(key, set()).update(refs)
		return reference_map
def _find_references ( self , items , depth = 0 , finded_ids = None ) : reference_map = { } if not items or depth >= self . max_depth : return reference_map if not hasattr ( items , 'items' ) : iterator = enumerate ( items ) else : iterator = iter ( items . items ( ) ) depth += 1 processed_ids = finded_ids if finded_ids is not None else set ( ) for k , item in iterator : if isinstance ( item , ( Document , EmbeddedDocument ) ) : for field_name , field in item . _fields . items ( ) : v = item . _data . get ( field_name , None ) if ( v and getattr ( field , 'document_type' , object ) is Taxonomy and isinstance ( v , Taxonomy ) and v . id not in processed_ids ) : processed_ids . add ( v . id ) reference_map . setdefault ( type ( v ) , set ( ) ) . add ( v . id ) elif isinstance ( v , DBRef ) and v . id not in processed_ids : processed_ids . add ( v . id ) try : reference_map . setdefault ( get_document ( v . cls ) , set ( ) ) . add ( v . id ) except AttributeError : reference_map . setdefault ( field . document_type , set ( ) ) . add ( v . id ) elif isinstance ( v , ( dict , SON ) ) and '_ref' in v and v [ '_ref' ] . id not in processed_ids : processed_ids . add ( v [ '_ref' ] . id ) reference_map . setdefault ( get_document ( v [ '_cls' ] ) , set ( ) ) . add ( v [ '_ref' ] . id ) elif isinstance ( v , ( dict , list , tuple ) ) and depth <= self . max_depth : field_cls = getattr ( getattr ( field , 'field' , None ) , 'document_type' , None ) references = self . _find_references ( v , depth , processed_ids ) for key , refs in references . items ( ) : if isinstance ( field_cls , ( Document , TopLevelDocumentMetaclass ) ) and key is Taxonomy : key = field_cls reference_map . setdefault ( key , set ( ) ) . update ( refs ) elif isinstance ( item , DBRef ) and item . id not in processed_ids : processed_ids . add ( item . id ) reference_map . setdefault ( item . collection , set ( ) ) . add ( item . id ) elif isinstance ( item , ( dict , SON ) ) and '_ref' in item and item [ '_ref' ] . id not in processed_ids : processed_ids . add ( item [ '_ref' ] . id ) reference_map . setdefault ( get_document ( item [ '_cls' ] ) , set ( ) ) . add ( item [ '_ref' ] . id ) elif isinstance ( item , ( dict , list , tuple ) ) and depth - 1 <= self . max_depth : references = self . _find_references ( item , depth - 1 , processed_ids ) for key , refs in references . items ( ) : reference_map . setdefault ( key , set ( ) ) . update ( refs ) return reference_map
Recursively finds all db references to be dereferenced
Recursively finds all db references to be dereferenced
"""
		Recursively finds all db references to be dereferenced

		:param items: The iterable (dict, list, queryset)
		:param depth: The current depth of recursion
		""" # if items and isinstance(items, list) and getattr(items[0], 'name', '') == 'child2': # 	import pudb; pudb.set_trace() # Determine the iterator to use # Recursively find dbreferences
self
items
The iterable (dict, list, queryset)
The iterable ( dict list queryset )
depth
The current depth of recursion
The current depth of recursion
finded_ids