Exemple #1
0
def get_farthest_cif():

    nodes = ParameterData.query()
    cif_type = CifData._query_type_string

    depth = models.DbPath.objects.filter(
        child__in=nodes, parent__type__contains=cif_type).distinct().order_by(
            '-depth').values_list('depth')[0][0]

    q = models.DbPath.objects.filter(parent__type__contains=cif_type,
                                     child__in=nodes,
                                     depth=depth).distinct()

    res = CifData.query(children__in=nodes,
                        child_paths__in=q).distinct().order_by('ctime')

    return list(res)
Exemple #2
0
def get_farthest_cif(with_attr=False):

    nodes = ParameterData.query().with_entities('id')
    cif_type = CifData._query_type_string

    depth = (sa.session.query(DbPath.depth).filter(
        DbPath.child_id.in_(nodes)).join(DbNode, DbPath.parent).filter(
            DbNode.type.like("%{}%".format(cif_type))).order_by(
                DbPath.depth.desc()).distinct()[0])[0]

    q = (DbPath.query.filter(DbPath.child_id.in_(nodes)).join(
        DbNode, DbPath.parent).filter(DbNode.type.like(
            "%{}%".format(cif_type))).filter(
                DbPath.depth == depth).distinct().with_entities(DbPath.id))

    res = (CifData.query(children__id__in=nodes,
                         child_paths__id__in=q).distinct().order_by(
                             DbNode.ctime))

    if not with_attr:
        res = res.options(defer(DbNode.attributes), defer(DbNode.extras))

    return res.all()