def group_info(group): return { 'name': utils._db_decode(group.group_name), 'id': group.entity_id, 'created_at': group.created_at, 'expire_date': group.expire_date, 'visibility': group.visibility, 'description': utils._db_decode(group.description), 'contexts': [row['spread'] for row in group.get_spread()], }
def get(self): """List groups.""" args = self.group_search_filter.parse_args() filters = {key: value for (key, value) in args.items() if value is not None} gr = Factory.get('Group')(db.connection) groups = list() for row in gr.search(**filters): group = dict(row) group.update({ 'id': utils._db_decode(group['name']), 'name': utils._db_decode(group['name']), }) group['description'] = utils._db_decode(group['description']) groups.append(group) return groups
def get(self): """List groups.""" args = self.group_search_filter.parse_args() filters = { key: value for (key, value) in args.items() if value is not None } gr = Factory.get('Group')(db.connection) groups = list() for row in gr.search(**filters): group = dict(row) group.update({ 'id': utils._db_decode(group['name']), 'name': utils._db_decode(group['name']), }) group['description'] = utils._db_decode(group['description']) groups.append(group) return groups
def get(self, id): """List groups an account is a member of.""" ac = find_account(id) args = self.account_groups_filter.parse_args() filters = {key: value for (key, value) in args.items() if value is not None} filters['member_id'] = ac.entity_id gr = Factory.get('Group')(db.connection) groups = list() for row in gr.search(**filters): group = dict(row) group.update({ 'id': utils._db_decode(group['name']), 'name': utils._db_decode(group['name']), 'description': utils._db_decode(group['description']) }) groups.append(group) return groups
"""Resource for a single person.""" @auth.require() @api.marshal_with(Person) def get(self, id): """Get person information""" pe = find_person(id) name_keys = [PersonName.get(k).attribute or k for k in PersonName] # Filter out appropriate fields from db_row objects names = [filter(lambda (k, _): k in name_keys, e.items()) for e in pe.get_all_names()] # decode name into unicode-object names = [dict(map(lambda (k, v): (k, utils._db_decode(v) if k == 'name' else v), e)) for e in names] return { 'id': pe.entity_id, 'contexts': [row['spread'] for row in pe.get_spread()], 'birth_date': pe.birth_date, 'created_at': pe.created_at, 'names': names } @api.route('/<int:id>/affiliations', endpoint='person-affiliations') @api.doc(params={'id': 'Person entity ID'}) class PersonAffiliationListResource(Resource): """Resource for person affiliations."""
class PersonResource(Resource): """Resource for a single person.""" @auth.require() @api.marshal_with(Person) def get(self, id): """Get person information""" pe = find_person(id) name_keys = [PersonName.get(k).attribute or k for k in PersonName] # Filter out appropriate fields from db_row objects names = [filter(lambda (k, _): k in name_keys, e.items()) for e in pe.get_all_names()] # decode name into unicode-object names = [dict(map(lambda (k, v): (k, utils._db_decode(v) if k == "name" else v), e)) for e in names] return { "id": pe.entity_id, "contexts": [row["spread"] for row in pe.get_spread()], "birth_date": pe.birth_date, "created_at": pe.created_at, "names": names, } @api.route("/<int:id>/affiliations", endpoint="person-affiliations") @api.doc(params={"id": "Person entity ID"}) class PersonAffiliationListResource(Resource): """Resource for person affiliations."""