Example #1
0
    def people_query(self, columns=None, **constraints):
        people_columns = [c.name for c in PeopleTable.columns]

        # Queryable columns are temporarily limited until
        # privacy filtering is implemented for this method.
        column_map = {
            'id': PeopleTable.c.id,
            'username': PeopleTable.c.username,
            #'human_name': PeopleTable.c.human_name,
            #'gpg_keyid': PeopleTable.c.gpg_keyid,
            #'ssh_key': PeopleTable.c.ssh_key,
            'email': PeopleTable.c.email,
            #'country_code': PeopleTable.c.country_code,
            #'creation': PeopleTable.c.creation,
            'ircnick': PeopleTable.c.ircnick,
            'status': PeopleTable.c.status,
            #'locale': PeopleTable.c.locale,
            #'timezone': PeopleTable.c.timezone,
            #'latitude': PeopleTable.c.latitude,
            #'longitude': PeopleTable.c.longitude,
            'group': GroupsTable.c.name,
            'group_type': GroupsTable.c.group_type,
            'role_status': PersonRolesTable.c.role_status,
            'role_type': PersonRolesTable.c.role_type,
            'role_approval': PersonRolesTable.c.approval,
        }

        if columns:
            cols = columns.split(',')
        else:
            # By default, return all of the people columns in column_map.
            cols = [c for c in people_columns if c in column_map]

        print cols
        print constraints

        groupjoin = []
        if 'group' in constraints \
            or 'group_type' in constraints \
            or 'role_status' in constraints \
            or 'role_type' in constraints:
            groupjoin = [PeopleTable.join(PersonRolesTable,
                PersonRolesTable.c.person_id == PeopleTable.c.id).join(GroupsTable,
                GroupsTable.c.id == PersonRolesTable.c.group_id)]

        try:
            query = select([column_map[c] for c in cols], from_obj=groupjoin)
        except KeyError:
            return dict(success=False, error='Invalid column requested.', data={})

        for k, v in constraints.iteritems():
            if k not in column_map:
                return dict(success=False,
                error='Invalid constraint specified.', data={})
            query = query.where(column_map[k].like(v))

        results = [dict(zip(cols, r)) for r in query.execute()]
        return dict(success=True, data=results)
Example #2
0
    def people_query(self, columns=None, **constraints):
        people_columns = [c.name for c in PeopleTable.columns]

        # Queryable columns are temporarily limited until
        # privacy filtering is implemented for this method.
        column_map = {
            'id': PeopleTable.c.id,
            'username': PeopleTable.c.username,
            #'human_name': PeopleTable.c.human_name,
            #'gpg_keyid': PeopleTable.c.gpg_keyid,
            #'ssh_key': PeopleTable.c.ssh_key,
            'email': PeopleTable.c.email,
            #'country_code': PeopleTable.c.country_code,
            #'creation': PeopleTable.c.creation,
            'ircnick': PeopleTable.c.ircnick,
            'status': PeopleTable.c.status,
            #'locale': PeopleTable.c.locale,
            #'timezone': PeopleTable.c.timezone,
            #'latitude': PeopleTable.c.latitude,
            #'longitude': PeopleTable.c.longitude,
            'group': GroupsTable.c.name,
            'group_type': GroupsTable.c.group_type,
            'role_status': PersonRolesTable.c.role_status,
            'role_type': PersonRolesTable.c.role_type,
            'role_approval': PersonRolesTable.c.approval,
        }

        if columns:
            cols = columns.split(',')
        else:
            # By default, return all of the people columns in column_map.
            cols = [c for c in people_columns if c in column_map]

        print cols
        print constraints

        groupjoin = []
        if 'group' in constraints \
            or 'group_type' in constraints \
            or 'role_status' in constraints \
            or 'role_type' in constraints:
            groupjoin = [
                PeopleTable.join(
                    PersonRolesTable,
                    PersonRolesTable.c.person_id == PeopleTable.c.id).join(
                        GroupsTable,
                        GroupsTable.c.id == PersonRolesTable.c.group_id)
            ]

        try:
            query = select([column_map[c] for c in cols], from_obj=groupjoin)
        except KeyError:
            return dict(success=False,
                        error='Invalid column requested.',
                        data={})

        for k, v in constraints.iteritems():
            if k not in column_map:
                return dict(success=False,
                            error='Invalid constraint specified.',
                            data={})
            query = query.where(column_map[k].like(v))

        results = [dict(zip(cols, r)) for r in query.execute()]
        return dict(success=True, data=results)