'Renders a list of all currently duplicate-bookmarked
records in this resource, with option to select two
and initiate the merge process from here
@param r: the S3Request
@param attr: the controller attributes for the request'

def duplicates(self, r, **attr):

    s3 = current.response.s3
    session_s3 = current.session.s3
    resource = self.resource
    tablename = self.tablename
    if (r.http == 'POST'):
        return self.merge(r, **attr)
    record_ids = []
    DEDUPLICATE = self.DEDUPLICATE
    if (DEDUPLICATE in session_s3):
        bookmarks = session_s3[DEDUPLICATE]
        if (tablename in bookmarks):
            record_ids = bookmarks[tablename]
    query = FS(resource._id.name).belongs(record_ids)
    resource.add_filter(query)
    representation = r.representation
    list_fields = resource.list_fields()
    get_vars = r.get_vars
    if (representation == 'aadata'):
        start = get_vars.get('displayStart', None)
        limit = get_vars.get('pageLength', None)
        draw = int((get_vars.draw or 0))
    else:
        start = 0
        limit = s3.ROWSPERPAGE
    if (limit is not None):
        try:
            start = int(start)
            limit = int(limit)
        except ValueError:
            start = None
            limit = None
    else:
        start = None
    if s3.dataTable_pageLength:
        display_length = s3.dataTable_pageLength
    else:
        display_length = 25
    if (limit is None):
        limit = (2 * display_length)
    totalrows = None
    if (representation == 'aadata'):
        (searchq, orderby, left) = resource.datatable_filter(list_fields, get_vars)
        if (searchq is not None):
            totalrows = resource.count()
            resource.add_filter(searchq)
    else:
        dt_sorting = {'iSortingCols': '1', 'sSortDir_0': 'asc'}
        if (len(list_fields) > 1):
            dt_sorting['bSortable_0'] = 'false'
            dt_sorting['iSortCol_0'] = '1'
        else:
            dt_sorting['bSortable_0'] = 'true'
            dt_sorting['iSortCol_0'] = '0'
        (orderby, left) = resource.datatable_filter(list_fields, dt_sorting)[1:]
    data = resource.select(list_fields, start=start, limit=limit, orderby=orderby, left=left, count=True, represent=True)
    displayrows = data['numrows']
    if (totalrows is None):
        totalrows = displayrows
    dt = S3DataTable(data['rfields'], data['rows'])
    datatable_id = 's3merge_1'
    if (representation == 'aadata'):
        output = dt.json(totalrows, displayrows, datatable_id, draw, dt_bulk_actions=[(current.T('Merge'), 'merge', 'pair-action')])
    elif (representation == 'html'):
        T = current.T
        output = {'title': T('De-duplicate    Records')}
        url = r.url(representation='aadata')
        items = dt.html(totalrows, displayrows, datatable_id, dt_ajax_url=url, dt_bulk_actions=[(T('Merge'), 'merge', 'pair-action')], dt_pageLength=display_length)
        output['items'] = items
        s3.actions = [{'label': str(T('View')), 'url': r.url(target='[id]', method='read'), '_class': 'action-btn'}]
        if (len(record_ids) < 2):
            output['add_btn'] = DIV(SPAN(T('You    need    to    have    at    least    2    records    in    this    list    in    order    to    merge    them.'), _style='float:left;padding-right:10px;'), A(T('Find    more'), _href=r.url(method='', id=0, component_id=0, vars={})))
        else:
            output['add_btn'] = DIV(SPAN(T("Select    2    records    from    this    list,    then    click    'Merge'.")))
        s3.dataTableID = [datatable_id]
        current.response.view = self._view(r, 'list.html')
    else:
        r.error(415, current.ERROR.BAD_FORMAT)
    return output
