def delete(self, r, **attr):
        """
            Delete record(s)

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

            @todo: update for link table components
        """

        output = dict()

        # Get table-specific parameters
        config = self._config
        deletable = config("deletable", True)
        delete_next = config("delete_next", None)

        # Check if deletable
        if not deletable:
            r.error(403, current.ERROR.NOT_PERMITTED,
                    next=r.url(method=""))

        # Get the target record ID
        record_id = self.record_id

        # Check permission to delete
        authorised = self._permitted()
        if not authorised:
            r.unauthorised()

        elif (r.interactive or r.representation == "aadata") and \
             r.http == "GET" and not record_id:
            output = self._datatable(r, **attr)
            if isinstance(output, dict):
                # Provide a confirmation form and a record list
                form = FORM(TABLE(TR(TD(self.settings.confirm_delete,
                                        _style="color:red"),
                                     TD(INPUT(_type="submit",
                                              _value=current.T("Delete"),
                                              _style="margin-left:10px")))))
                output["form"] = form
                current.response.view = self._view(r, "delete.html")
            else:
                # @todo: sorting not working yet
                return output

        elif r.interactive and (r.http == "POST" or
                                r.http == "GET" and record_id):
            # Delete the records, notify success and redirect to the next view
            numrows = self.resource.delete(format=r.representation)
            if 1 > numrows:
                message = "%s %s" % (numrows, current.T("records deleted"))
            elif numrows == 1:
                message = self.crud_string(self.tablename,
                                           "msg_record_deleted")
            else:
                r.error(404, self.resource.error, next=r.url(method=""))
            current.response.confirmation = message
            r.http = "DELETE" # must be set for immediate redirect
            self.next = delete_next or r.url(method="")

        elif r.http == "DELETE" or \
             r.representation == "json" and r.http == "POST" and record_id:

            numrows = None
            resource = self.resource

            recursive = r.get_vars.get("recursive", False)
            if recursive and recursive.lower() in ("1", "true"):
                # Try recursive deletion of the whole hierarchy branch
                # => falls back to normal delete if no hierarchy configured
                from s3hierarchy import S3Hierarchy
                h = S3Hierarchy(resource.tablename)
                if h.config:
                    node_ids = None
                    pkey = h.pkey
                    if str(pkey) == str(resource._id):
                        node_ids = [record_id]
                    else:
                        # Need to lookup the hierarchy node key
                        query = (resource._id == record_id)
                        row = current.db(query).select(pkey,
                                                       limitby=(0, 1)).first()
                        if row:
                            node_ids = [row[pkey]]
                    numrows = h.delete(node_ids) if node_ids else 0
                    if not numrows:
                        # Cascade failed, do not fall back
                        # @todo: propagate the original error
                        resource.error = current.T("Deletion failed")
                        numrows = 0

            if numrows is None:
                # Delete the records and return a JSON message
                numrows = self.resource.delete(format=r.representation)

            if numrows > 1:
                message = "%s %s" % (numrows, current.T("records deleted"))
            elif numrows == 1:
                message = self.crud_string(self.tablename,
                                           "msg_record_deleted")
            else:
                r.error(404, resource.error, next=r.url(method=""))

            item = current.xml.json_message(message=message)
            current.response.view = "xml.html"
            output.update(item=item)

        else:
            r.error(405, current.ERROR.BAD_METHOD)

        return output

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3/s3crud.py/S3CRUD.delete/swapped operands of `>`