def _get_entity_ids(field_name, attrs):
    """Find the IDs for a one to many relationship.

    The server may return JSON data in the following forms for a
    :class:`nailgun.entity_fields.OneToManyField`::

        'user': [{'id': 1, …}, {'id': 42, …}]
        'users': [{'id': 1, …}, {'id': 42, …}]
        'user_ids': [1, 42]

    Search ``attrs`` for a one to many ``field_name`` and return its ID.

    :param field_name: A string. The name of a field.
    :param attrs: A dict. A JSON payload as returned from a server.
    :returns: An iterable of entity IDs.

    """
    field_name_ids = field_name + '_ids'
    plural_field_name = pluralize(field_name)
    if field_name_ids in attrs:
        return attrs[field_name_ids]
    elif field_name in attrs:
        return [entity['id'] for entity in attrs[field_name]]
    elif plural_field_name in attrs:
        return [entity['id'] for entity in attrs[plural_field_name]]
    else:
        raise MissingValueError(
            'Cannot find a value for the "{0}" field. Searched for keys named '
            '{1}, but available keys are {2}.'
            .format(
                field_name,
                (field_name_ids, field_name, plural_field_name),
                attrs.keys()
            )
        )
def _get_entity_ids ( field_name , attrs ) : field_name_ids = field_name + '_ids' plural_field_name = pluralize ( field_name ) if field_name_ids in attrs : return attrs [ field_name_ids ] elif field_name in attrs : return [ entity [ 'id' ] for entity in attrs [ field_name ] ] elif plural_field_name in attrs : return [ entity [ 'id' ] for entity in attrs [ plural_field_name ] ] else : raise MissingValueError ( 'Cannot find a value for the "{0}" field. Searched for keys named ' '{1}, but available keys are {2}.' . format ( field_name , ( field_name_ids , field_name , plural_field_name ) , attrs . keys ( ) ) )
Find the IDs for a one to many relationship.

    The server may return JSON data in the following forms for a
    :class:`nailgun.entity_fields.OneToManyField`::

        'user': [{'id': 1, …}, {'id': 42, …}]
        'users': [{'id': 1, …}, {'id': 42, …}]
        'user_ids': [1, 42]

    Search ``attrs`` for a one to many ``field_name`` and return its ID.

    :param field_name: A string. The name of a field.
    :param attrs: A dict. A JSON payload as returned from a server.
    :returns: An iterable of entity IDs.