'Delete a filter, responds to POST filter.json?delete=
@param r: the S3Request
@param attr: additional controller parameters'

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

    auth = current.auth
    if auth.s3_logged_in():
        pe_id = current.auth.user.pe_id
    else:
        pe_id = None
    if (not pe_id):
        r.unauthorised()
    source = r.body
    source.seek(0)
    try:
        data = json.load(source)
    except ValueError:
        r.error(501, current.ERROR.BAD_SOURCE)
    db = current.db
    s3db = current.s3db
    table = s3db.pr_filter
    record = None
    record_id = data.get('id')
    if record_id:
        query = ((table.id == record_id) & (table.pe_id == pe_id))
        record = db(query).select(table.id, limitby=(0, 1)).first()
    if (not record):
        r.error(501, current.ERROR.BAD_RECORD)
    resource = s3db.resource('pr_filter', id=record_id)
    success = resource.delete(format=r.representation)
    if (not success):
        raise (400, resource.error)
    else:
        current.response.headers['Content-Type'] = 'application/json'
        return current.xml.json_message(deleted=record_id)
