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]
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
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
def get_latest_root( self ): return Code.find(Code.nation == self.nation, Code.depth == 0).order_by( self.get_id_field() ).last()