def create_custom_field(connection, cf_type, cf_name, auto_attached, value_names=None, bundle_policy="0"):
    """
    Creates custom field prototype(if not exist) and sets default values bundle if needed

     Args:
        connection: An opened Connection instance.
        cf_type: Type of custom field to be created
        cf_name: Name of custom field that should be created (if not exists)
        auto_attached: If this field should be auto attached or not.
        value_names: Values, that should be attached with this cf by default.
                     If None, no bundle is created to this field, if empty, empty bundle is created.
        bundle_policy: ???
    Raises:
        LogicException: If custom field already exists, but has wrong type.
        YouTrackException: If something is wrong with queries.
    """
    if (value_names is None) and (not auto_attached or "[" not in cf_type):
        _create_custom_field_prototype(connection, cf_type, cf_name, auto_attached)
        return
    if value_names is None:
        value_names = set([])
    else:
        value_names = set(value_names)
    field = _get_custom_field(connection, cf_name)
    if field is not None:
        if hasattr(field, "defaultBundle"):
            bundle = connection.get_bundle(field.type, field.defaultBundle)
        elif field.autoAttached:
            return
        else:
            bundle = create_bundle_safe(connection, cf_name + "_bundle", cf_type)
    else:
        bundle = create_bundle_safe(connection, cf_name + "_bundle", cf_type)
        _create_custom_field_prototype(connection, cf_type, cf_name, auto_attached,
                                       {"defaultBundle": bundle.name,
                                        "attachBundlePolicy": bundle_policy})
    for value_name in value_names:
        try:
            connection.add_value_to_bundle(bundle, value_name)
        except YouTrackException:
            pass
def create_custom_field ( connection , cf_type , cf_name , auto_attached , value_names = None , bundle_policy = "0" ) : if ( value_names is None ) and ( not auto_attached or "[" not in cf_type ) : _create_custom_field_prototype ( connection , cf_type , cf_name , auto_attached ) return if value_names is None : value_names = set ( [ ] ) else : value_names = set ( value_names ) field = _get_custom_field ( connection , cf_name ) if field is not None : if hasattr ( field , "defaultBundle" ) : bundle = connection . get_bundle ( field . type , field . defaultBundle ) elif field . autoAttached : return else : bundle = create_bundle_safe ( connection , cf_name + "_bundle" , cf_type ) else : bundle = create_bundle_safe ( connection , cf_name + "_bundle" , cf_type ) _create_custom_field_prototype ( connection , cf_type , cf_name , auto_attached , { "defaultBundle" : bundle . name , "attachBundlePolicy" : bundle_policy } ) for value_name in value_names : try : connection . add_value_to_bundle ( bundle , value_name ) except YouTrackException : pass
Creates custom field prototype(if not exist) and sets default values bundle if needed

     Args:
        connection: An opened Connection instance.
        cf_type: Type of custom field to be created
        cf_name: Name of custom field that should be created (if not exists)
        auto_attached: If this field should be auto attached or not.
        value_names: Values, that should be attached with this cf by default.
                     If None, no bundle is created to this field, if empty, empty bundle is created.
        bundle_policy: ???
    Raises:
        LogicException: If custom field already exists, but has wrong type.
        YouTrackException: If something is wrong with queries.