'Render a read- or edit-row.
@param table: the database table
@param item: the data
@param fields: the fields to render (list of strings)
@param readonly: render a read-row (otherwise edit-row)
@param editable: whether the record can be edited
@param deletable: whether the record can be deleted
@param multiple: whether multiple records can be added
@param index: the row index
@param layout: the subform layout (S3SQLSubFormLayout)
@param attributes: HTML attributes for the row'

def _render_item(self, table, item, fields, readonly=True, editable=False, deletable=False, multiple=True, index='none', layout=None, **attributes):

    s3 = current.response.s3
    rowtype = ((readonly and 'read') or 'edit')
    pkey = table._id.name
    data = {}
    formfields = []
    formname = self._formname()
    widgets = self.widgets
    for f in fields:
        fname = f['name']
        idxname = ('%s_i_%s_%s_%s' % (formname, fname, rowtype, index))
        if (not readonly):
            parent = table._tablename.split('_', 1)[1]
            caller = ('sub_%s_%s' % (formname, idxname))
            popup = Storage(parent=parent, caller=caller)
        else:
            popup = None
        label = f.get('label', DEFAULT)
        widget = widgets.get(fname, DEFAULT)
        if ((widget is DEFAULT) and (str(table[fname].type) == 'upload')):
            widget = S3UploadWidget.widget
        formfield = self._rename_field(table[fname], idxname, comments=False, label=label, popup=popup, skip_post_validation=True, widget=widget)
        if ('filterby' in self.options):
            options = self._filterby_options(fname)
            if options:
                if (len(options) < 2):
                    requires = IS_IN_SET(options, zero=None)
                else:
                    requires = IS_IN_SET(options)
                formfield.requires = SKIP_POST_VALIDATION(requires)
        defaults = self._filterby_defaults()
        if (defaults and (fname in defaults)):
            default = defaults[fname]['value']
            formfield.default = default
        if ((index is not None) and item and (fname in item)):
            if (formfield.type == 'upload'):
                filename = item[fname]['value']
                if (current.request.env.request_method == 'POST'):
                    if (('_index' in item) and item.get('_changed', False)):
                        rowindex = item['_index']
                        filename = self._store_file(table, fname, rowindex)
                data[idxname] = filename
            else:
                value = item[fname]['value']
                if (type(value) is unicode):
                    value = value.encode('utf-8')
                widget = formfield.widget
                if isinstance(widget, S3Selector):
                    (value, error) = (widget.parse(value).get('id'), None)
                else:
                    (value, error) = s3_validate(table, fname, value)
                if error:
                    value = None
                data[idxname] = value
        formfields.append(formfield)
    if (not data):
        data = None
    elif (pkey not in data):
        data[pkey] = None
    subform_name = ('sub_%s' % formname)
    rowstyle = (layout.rowstyle_read if readonly else layout.rowstyle)
    subform = SQLFORM.factory(record=data, showid=False, formstyle=rowstyle, upload=s3.download_url, readonly=readonly, table_name=subform_name, separator=':', submit=False, buttons=[], *formfields)
    subform = subform[0]
    subform_class = subform['_class']
    subform.update(**attributes)
    if subform_class:
        subform.add_class(subform_class)
    if multiple:
        layout.actions(subform, formname, index, item=item, readonly=readonly, editable=editable, deletable=deletable)
    return subform
