web/contentment/taxonomy.py
def insert(self, index, child):
		"""Add an asset, specified by the parameter, as a child of this asset."""
		
		parent = self.clone().first()
		
		log.info("Inserting asset.", extra=dict(asset=parent.id, index=index, child=getattr(child, 'id', child)))
		
		# Detach the new child (and thus it's own child nodes).
		child = (self.base_query.get(id=child) if isinstance(child, ObjectId) else child).detach(False)
		
		if index < 0:
			_max = self.base_query(parent=parent).order_by('-order').scalar('order').first()
			index = 0 if _max is None else (_max + 1)
		
		q = self.base_query(parent=parent, order__gte=index).update(inc__order=1)
		
		child.order = index
		
		child.path = parent.path + '/' + child.name
		child.parent = parent
		child.parents = list(parent.parents)
		child.parents.append(parent)
		
		child = child.save()
		
		child.contents.update(__raw__={
				'$push': {
						'parents': {
								'$each': [
										i.to_dbref() for i in child.parents
									],
								'$position': 0
							}
					}
			})
		
		child._normpath()
		
		return self
Add an asset, specified by the parameter, as a child of this asset.
Add an asset, specified by the parameter, as a child of this asset.
Add an asset specified by the parameter as a child of this asset .
def insert(self, index, child):
		parent = self.clone().first()
		log.info("Inserting asset.", extra=dict(asset=parent.id, index=index, child=getattr(child, 'id', child)))
		child = (self.base_query.get(id=child) if isinstance(child, ObjectId) else child).detach(False)
		if index < 0:
			_max = self.base_query(parent=parent).order_by('-order').scalar('order').first()
			index = 0 if _max is None else (_max + 1)
		q = self.base_query(parent=parent, order__gte=index).update(inc__order=1)
		child.order = index
		child.path = parent.path + '/' + child.name
		child.parent = parent
		child.parents = list(parent.parents)
		child.parents.append(parent)
		child = child.save()
		child.contents.update(__raw__={
				'$push': {
						'parents': {
								'$each': [
										i.to_dbref() for i in child.parents
									],
								'$position': 0
							}
					}
			})
		child._normpath()
		return self
def insert ( self , index , child ) : parent = self . clone ( ) . first ( ) log . info ( "Inserting asset." , extra = dict ( asset = parent . id , index = index , child = getattr ( child , 'id' , child ) ) ) child = ( self . base_query . get ( id = child ) if isinstance ( child , ObjectId ) else child ) . detach ( False ) if index < 0 : _max = self . base_query ( parent = parent ) . order_by ( '-order' ) . scalar ( 'order' ) . first ( ) index = 0 if _max is None else ( _max + 1 ) q = self . base_query ( parent = parent , order__gte = index ) . update ( inc__order = 1 ) child . order = index child . path = parent . path + '/' + child . name child . parent = parent child . parents = list ( parent . parents ) child . parents . append ( parent ) child = child . save ( ) child . contents . update ( __raw__ = { '$push' : { 'parents' : { '$each' : [ i . to_dbref ( ) for i in child . parents ] , '$position' : 0 } } } ) child . _normpath ( ) return self
Add an asset, specified by the parameter, as a child of this asset.
Add an asset specified by the parameter as a child of this asset .
"""Add an asset, specified by the parameter, as a child of this asset.""" # Detach the new child (and thus it's own child nodes).
self
index
child