def select(self, r, **attr):
        """
            Filtered datatable/datalist

            @param r: the S3Request
            @param attr: dictionary of parameters for the method handler
        """

        resource = self.resource

        tablename = resource.tablename
        get_config = resource.get_config

        list_fields = get_config("list_fields", None)

        representation = r.representation
        if representation in ("html", "iframe", "aadata", "dl", "popup"):

            hide_filter = self.hide_filter
            filter_widgets = get_config("filter_widgets", None)

            show_filter_form = False
            if filter_widgets and not hide_filter and \
               ("aadata", "dl") not in representation:
                show_filter_form = True
                # Apply filter defaults (before rendering the data!)
                from s3filter import S3FilterForm
                S3FilterForm.apply_filter_defaults(r, resource)

            # Data
            list_type = attr.get("list_type", "datatable")
            if list_type == "datalist":
                filter_ajax = True
                target = "datalist"
                output = self._datalist(r, **attr)
            else:
                # Hide datatable filter box if we have a filter form
                if filter_widgets and not hide_filter:
                    dtargs = attr.get("dtargs", {})
                    if "dt_searching" not in dtargs:
                        dtargs["dt_searching"] = False
                    _attr = dict(attr)
                    _attr["dtargs"] = dtargs
                else:
                    _attr = attr
                filter_ajax = True
                target = "datatable"
                output = self._datatable(r, **_attr)

            if representation in ("aadata", "dl"):
                return output

            output["list_type"] = list_type

            crud_string = self.crud_string

            # Page title
            if representation != "iframe":
                if r.component:
                    title = crud_string(r.tablename, "title_display")
                else:
                    title = crud_string(self.tablename, "title_list")
                output["title"] = title

            # Filter-form
            if show_filter_form:

                # Where to retrieve filtered data from:
                filter_submit_url = attr.get("filter_submit_url")
                if not filter_submit_url:
                    _vars = self._remove_filters(r.get_vars)
                    filter_submit_url = r.url(vars=_vars)

                # Where to retrieve updated filter options from:
                filter_ajax_url = attr.get("filter_ajax_url",
                                           r.url(method="filter",
                                                 vars={},
                                                 representation="options"))

                filter_clear = get_config("filter_clear",
                                          current.deployment_settings.get_ui_filter_clear())
                filter_formstyle = get_config("filter_formstyle", None)
                filter_submit = get_config("filter_submit", True)
                filter_form = S3FilterForm(filter_widgets,
                                           clear=filter_clear,
                                           formstyle=filter_formstyle,
                                           submit=filter_submit,
                                           ajax=filter_ajax,
                                           url=filter_submit_url,
                                           ajaxurl=filter_ajax_url,
                                           _class="filter-form",
                                           _id="%s-filter-form" % target
                                           )
                fresource = current.s3db.resource(resource.tablename)
                alias = resource.alias if r.component else None
                output["list_filter_form"] = filter_form.html(fresource,
                                                              r.get_vars,
                                                              target=target,
                                                              alias=alias
                                                              )
            else:
                # Render as empty string to avoid the exception in the view
                output["list_filter_form"] = ""

            # Add-form or -button
            insertable = get_config("insertable", True)
            if insertable:

                addbtn = get_config("addbtn", False)
                listadd = get_config("listadd", True)

                if listadd:
                    # Save the view
                    response = current.response
                    view = response.view

                    # JS Cancel (no redirect with embedded form)
                    s3 = response.s3
                    cancel = s3.cancel
                    s3.cancel = {"hide": "list-add", "show": "show-add-btn"}

                    # Add a hidden add-form and a button to activate it
                    form = self.create(r, **attr).get("form", None)
                    if form is not None:
                        output["form"] = form
                        addtitle = self.crud_string(tablename, "label_create")
                        output["addtitle"] = addtitle
                        showadd_btn = self.crud_button(None,
                                                       tablename=tablename,
                                                       name="label_create",
                                                       icon="add",
                                                       _id="show-add-btn")
                        output["showadd_btn"] = showadd_btn

                    # Restore the view
                    response.view = view
                    s3.cancel = cancel

                elif addbtn:
                    # Add an action-button linked to the create view
                    buttons = self.render_buttons(r, ["add"], **attr)
                    if buttons:
                        output["buttons"] = buttons

            return output

        elif representation == "plain":

            if resource.count() == 1:
                # Provide the record
                # (used by Map's Layer Properties window)
                resource.load()
                r.record = resource.records().first()
                if r.record:
                    r.id = r.record.id
                    self.record_id = self._record_id(r)
                    if "update" in r.get_vars and \
                       self._permitted(method="update"):
                        items = self.update(r, **attr).get("form", None)
                    else:
                        items = self.sqlform(request=self.request,
                                             resource=self.resource,
                                             record_id=r.id,
                                             readonly=True,
                                             format=representation)
                else:
                    raise HTTP(404, body="Record not Found")
            else:
                rows = resource.select(list_fields,
                                       limit=None,
                                       as_rows=True)
                if rows:
                    items = rows.as_list()
                else:
                    items = []

            current.response.view = "plain.html"
            return dict(item=items)

        elif representation == "csv":

            exporter = S3Exporter().csv
            return exporter(resource)

        elif representation == "json":

            get_vars = self.request.get_vars

            # Start/limit
            start, limit = self._limits(get_vars)

            # Render extra "_tooltip" field for each row?
            tooltip = get_vars.get("tooltip", None)

            # Represent?
            represent = get_vars.get("represent", False)
            if represent and represent != "0":
                represent = True

            exporter = S3Exporter().json
            return exporter(resource,
                            start=start,
                            limit=limit,
                            represent=represent,
                            tooltip=tooltip)

        elif representation == "pdf":

            report_hide_comments = get_config("report_hide_comments", None)
            report_filename = get_config("report_filename", None)
            report_formname = get_config("report_formname", None)

            exporter = S3Exporter().pdf
            return exporter(resource,
                            request=r,
                            list_fields=list_fields,
                            report_hide_comments = report_hide_comments,
                            report_filename = report_filename,
                            report_formname = report_formname,
                            **attr)

        elif representation == "shp":
            exporter = S3Exporter().shp
            return exporter(resource,
                            list_fields=list_fields,
                            **attr)

        elif representation == "svg":
            exporter = S3Exporter().svg
            return exporter(resource,
                            list_fields=list_fields,
                            **attr)

        elif representation == "xls":
            report_groupby = get_config("report_groupby", None)
            exporter = S3Exporter().xls
            return exporter(resource,
                            list_fields=list_fields,
                            report_groupby=report_groupby,
                            **attr)

        elif representation == "msg":
            if r.http == "POST":
                from s3notify import S3Notifications
                return S3Notifications.send(r, resource)
            else:
                r.error(405, current.ERROR.BAD_METHOD)

        else:
            r.error(415, current.ERROR.BAD_FORMAT)

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3/s3crud.py/S3CRUD.select/swapped operands of `not in`