def get_all_baseurls(tenant_id, session=None): if not session: session = get_session() tba = aliased(models.TenantBaseURLAssociation) baseUrls = aliased(models.BaseUrls) return session.query(baseUrls).join((tba, tba.baseURLs_id == baseUrls.id)).\ filter(tba.tenant_id == tenant_id).all()
def user_groups_get_all(user_id, session=None): if not session: session = get_session() uga = aliased(models.UserGroupAssociation) group = aliased(models.Group) return session.query(group, uga).\ join((uga, uga.group_id == group.id)).\ filter(uga.user_id == user_id).order_by( group.id).all()
def get_by_user_get_page_markers(user_id, marker, limit, session=None): if not session: session = get_session() uga = aliased(models.UserGroupAssociation) group = aliased(models.Group) first, _firstassoc = session.query(group, uga).\ join((uga, uga.group_id == group.id)).\ filter(uga.user_id == user_id).\ order_by(group.id).first() last, _lastassoc = session.query(group, uga).\ join((uga, uga.group_id == group.id)).\ filter(uga.user_id == user_id).\ order_by(group.id.desc()).first() if first is None: return (None, None) if marker is None: marker = first.id next = session.query(group, uga).join( (uga, uga.group_id == group.id)).\ filter(uga.user_id == user_id).\ filter("id>=:marker").params( marker='%s' % marker).order_by( group.id).limit(int(limit)).all() prev = session.query(group, uga).join( (uga, uga.group_id == group.id)).\ filter(uga.user_id == user_id).\ filter("id < :marker").params( marker='%s' % marker).order_by( group.id).limit(int(limit) + 1).all() next_len = len(next) prev_len = len(prev) if next_len == 0: next = last else: for t, _a in next: next = t if prev_len == 0: prev = first else: for t, _a in prev: prev = t if first.id == marker: prev = None else: prev = prev.id if marker == last.id: next = None else: next = next.id return (prev, next)
def tenants_for_user_get_page(user, marker, limit, session=None): if not session: session = get_session() ura = aliased(models.UserRoleAssociation) tenant = aliased(models.Tenant) q1 = session.query(tenant).join((ura, ura.tenant_id == tenant.id)).\ filter(ura.user_id == user.id) q2 = session.query(tenant).filter(tenant.id == user.tenant_id) q3 = q1.union(q2) if marker: return q3.filter("tenant.id>:marker").params(\ marker='%s' % marker).order_by(\ tenant.id.desc()).limit(limit).all() else: return q3.order_by(tenant.id.desc()).limit(limit).all()
def get_by_user_get_page(user_id, marker, limit, session=None): if not session: session = get_session() uga = aliased(models.UserGroupAssociation) group = aliased(models.Group) if marker: return session.query(group, uga).join(\ (uga, uga.group_id == group.id)).\ filter(uga.user_id == user_id).\ filter("id>=:marker").params( marker='%s' % marker).order_by( group.id).limit(limit).all() else: return session.query(group, uga).\ join((uga, uga.group_id == group.id)).\ filter(uga.user_id == user_id).order_by( group.id).limit(limit).all()
def users_tenant_group_get_page_markers(group_id, marker, limit, session=None): if not session: session = get_session() uga = aliased(models.UserGroupAssociation) user = aliased(models.User) first = session.query(models.User).order_by(\ models.User.id).first() last = session.query(models.User).order_by(\ models.User.id.desc()).first() if first is None: return (None, None) if marker is None: marker = first.id next = session.query(user).join( (uga, uga.user_id == user.id)).\ filter(uga.group_id == group_id).\ filter("id > :marker").params(\ marker='%s' % marker).order_by(\ user.id).limit(limit).all() prev = session.query(user).join(\ (uga, uga.user_id == user.id)).\ filter(uga.group_id == group_id).\ filter("id < :marker").params(\ marker='%s' % marker).order_by(\ user.id.desc()).limit(int(limit)).all() if len(next) == 0: next = last else: for t in next: next = t if len(prev) == 0: prev = first else: for t in prev: prev = t if prev.id == marker: prev = None else: prev = prev.id if next.id == last.id: next = None else: next = next.id return (prev, next)
def tenants_for_user_get_page_markers(user, marker, limit, session=None): if not session: session = get_session() ura = aliased(models.UserRoleAssociation) tenant = aliased(models.Tenant) q1 = session.query(tenant).join((ura, ura.tenant_id == tenant.id)).\ filter(ura.user_id == user.id) q2 = session.query(tenant).filter(tenant.id == user.tenant_id) q3 = q1.union(q2) first = q3.order_by(\ tenant.id).first() last = q3.order_by(\ tenant.id.desc()).first() if first is None: return (None, None) if marker is None: marker = first.id next = q3.filter(tenant.id > marker).order_by(\ tenant.id).limit(limit).all() prev = q3.filter(tenant.id > marker).order_by(\ tenant.id.desc()).limit(int(limit)).all() if len(next) == 0: next = last else: for t in next: next = t if len(prev) == 0: prev = first else: for t in prev: prev = t if prev.id == marker: prev = None else: prev = prev.id if next.id == last.id: next = None else: next = next.id return (prev, next)
def users_get_page(marker, limit, session=None): if not session: session = get_session() user = aliased(models.User) if marker: return session.query(user).\ filter("id>=:marker").params( marker='%s' % marker).order_by( "id").limit(limit).all() else: return session.query(user).\ order_by("id").limit(limit).all()
def ref_get_by_tenant_get_page_markers(tenant_id, marker, limit, session=None): if not session: session = get_session() tba = aliased(models.TenantBaseURLAssociation) first = session.query(tba).\ filter(tba.tenant_id == tenant_id).\ order_by(tba.id).first() last = session.query(tba).\ filter(tba.tenant_id == tenant_id).\ order_by(tba.id.desc()).first() if first is None: return (None, None) if marker is None: marker = first.id next = session.query(tba).\ filter(tba.tenant_id == tenant_id).\ filter("id>=:marker").params( marker='%s' % marker).order_by( tba.id).limit(int(limit)).all() prev = session.query(tba).\ filter(tba.tenant_id == tenant_id).\ filter("id < :marker").params( marker='%s' % marker).order_by( tba.id).limit(int(limit) + 1).all() next_len = len(next) prev_len = len(prev) if next_len == 0: next = last else: for t in next: next = t if prev_len == 0: prev = first else: for t in prev: prev = t if first.id == marker: prev = None else: prev = prev.id if marker == last.id: next = None else: next = next.id return (prev, next)
def users_get_page_markers(marker, limit, \ session=None): if not session: session = get_session() user = aliased(models.User) first = session.query(user).\ order_by(user.id).first() last = session.query(user).\ order_by(user.id.desc()).first() if first is None: return (None, None) if marker is None: marker = first.id next = session.query(user).\ filter("id > :marker").params(\ marker='%s' % marker).order_by(user.id).\ limit(int(limit)).all() prev = session.query(user).\ filter("id < :marker").params( marker='%s' % marker).order_by( user.id.desc()).limit(int(limit)).all() next_len = len(next) prev_len = len(prev) if next_len == 0: next = last else: for t in next: next = t if prev_len == 0: prev = first else: for t in prev: prev = t if first.id == marker: prev = None else: prev = prev.id if marker == last.id: next = None else: next = next.id return (prev, next)