def by_aa(cls, aa): result = {} values = (DBSession.query( cls.name, cls.value, func.count(cls.value), cls.aaid).filter_by(aaid=aa.authorizable_attribute_id).group_by( cls.name, cls.value).all()) for v in values: existent_list = result.get(v[0], []) existent_list.append({v[1]: v[2]}) if v[2] >= aa.optional_k(v[0]): result[v[0]] = existent_list result["total"] = ValidatedCredentials.total_by_aaid( aa.authorizable_attribute_id) return result
def aggregate(cls): result = {} values = (DBSession.query(cls.name, cls.value, func.count(cls.value), cls.aaid).group_by(cls.name, cls.value).all()) for v in values: existent_list = result.get(v[0], []) existent_list.append({v[1]: v[2]}) aa = AuthorizableAttribute.by_aa_id(v[3]) if v[2] >= aa.optional_k(v[0]): result[v[0]] = existent_list result["total"] = ValidatedCredentials.total() return result
def total(cls): return DBSession.query(cls).count()
def exists(cls, aaid, value): return (DBSession.query(cls).filter_by(aaid=aaid).filter_by( value=json.dumps(value)).first())
def by_aa_id(cls, aa_id): return DBSession.query(cls).filter_by( authorizable_attribute_id=aa_id).first()
def total_by_aaid(cls, aaid): return DBSession.query(cls).filter_by(aaid=aaid).count()