'Returns a linker function for the record ID column in list views
@param r: the S3Request
@param authorised: user authorised for update
(override internal check)
@param update: provide link to update rather than to read
@param native: link to the native controller rather than to
component controller'

def _linkto(self, r, authorised=None, update=None, native=False):

    c = None
    f = None
    s3db = current.s3db
    (prefix, name, table, tablename) = r.target()
    permit = current.auth.s3_has_permission
    if (authorised is None):
        authorised = permit('update', tablename)
    if (authorised and update):
        linkto = s3db.get_config(tablename, 'linkto_update', None)
    else:
        linkto = s3db.get_config(tablename, 'linkto', None)
    if (r.component and native):
        c = prefix
        f = name
    if (r.representation == 'iframe'):
        if current.deployment_settings.get_ui_iframe_opens_full():
            iframe_safe = (lambda url: s3_set_extension(url, 'html'))
        else:
            iframe_safe = (lambda url: s3_set_extension(url, 'iframe'))
    else:
        iframe_safe = False
    def list_linkto(record_id, r=r, c=c, f=f, linkto=linkto, update=(authorised and update)):
        if linkto:
            try:
                url = str(linkto(record_id))
            except TypeError:
                url = (linkto % record_id)
        else:
            get_vars = self._linkto_vars(r)
            if r.component:
                if (r.link and (not r.actuate_link())):
                    if str(record_id).isdigit():
                        _id = r.link.table._id
                        _id.represent = (lambda opt, link=r.link, master=r.id: link.component_id(master, opt))
                        record_id = r.link.component_id(r.id, record_id)
                if (c and f):
                    args = [record_id]
                else:
                    c = r.controller
                    f = r.function
                    args = [r.id, r.component_name, record_id]
                if update:
                    url = str(URL(r=r, c=c, f=f, args=(args + ['update']), vars=get_vars))
                else:
                    url = str(URL(r=r, c=c, f=f, args=(args + ['read']), vars=get_vars))
            else:
                args = [record_id]
                if update:
                    url = str(URL(r=r, c=c, f=f, args=(args + ['update']), vars=get_vars))
                else:
                    url = str(URL(r=r, c=c, f=f, args=(args + ['read']), vars=get_vars))
        if iframe_safe:
            url = iframe_safe(url)
        return url
    return list_linkto
