예제 #1
0
 def get_root( self, id ):
     ids = self.get_ids()
     id = self.coerce_id(id)
     if id not in ids:
         raise ValueError
     else:
         r = Code.find( self.get_id_field() == id, Code.depth == 0, Code.nation == self.nation )
         return r[0]
예제 #2
0
 def getChild( self, id, parent, depth=None ):
     depth = depth if depth else parent.depth + 1
     r = Code.find(Code.nation == self.nation, Code.depth == depth, Code.cid == id, Code.rev == parent.rev, Code.parent == parent)
     if r.count():
         return r.one()
     else:
         c = store.add(Code())
         c.depth = depth
         c.cid = id
         c.parent = parent
         c.rev = parent.rev
         c.nation = self.nation
         return c
예제 #3
0
 def get_ids( self ):
     r = Code.find(Code.depth == 0, Code.nation == self.nation)
     ids = tuple( set ( [c.rp for c in r] ) )
     return ids            
예제 #4
0
 def get_latest_root( self ):
     return Code.find(Code.nation == self.nation, Code.depth == 0).order_by( self.get_id_field() ).last()