'Generate a CRUD action button
@param label: the link label (None if using CRUD string)
@param tablename: the name of table for CRUD string selection
@param name: name of CRUD string for the button label
@param icon: name of the icon (e.g. "add")
@param _href: the target URL
@param _id: the HTML id of the link
@param _class: the HTML class of the link
@param _title: the HTML title of the link
@param _target: the HTML target of the link
@keyword custom: custom CRUD button (just add classes)'

@staticmethod
def crud_button(label=None, tablename=None, name=None, icon=None, _href=None, _id=None, _class=None, _title=None, _target=None, **attr):

    settings = current.deployment_settings
    bootstrap = (settings.ui.formstyle == 'bootstrap')
    if ('custom' in attr):
        custom = attr['custom']
        if (custom is None):
            custom = ''
        elif (bootstrap and hasattr(custom, 'add_class')):
            custom.add_class('btn    btn-primary')
        return custom
    if ((_class is None) and (not bootstrap)):
        _class = 'action-btn'
    if name:
        labelstr = S3CRUD.crud_string(tablename, name)
    else:
        labelstr = str(label)
    if (icon and settings.get_ui_use_button_icons()):
        button = A(ICON(icon), labelstr, _id=_id, _class=_class)
    else:
        button = A(labelstr, _id=_id, _class=_class)
    if _href:
        button['_href'] = _href
    if _title:
        button['_title'] = _title
    if _target:
        button['_target'] = _target
    if bootstrap:
        button.add_class('btn    btn-primary')
    return button
