From e6ac313d0f6cee57ba1e9e0d47e25c691b203966 Mon Sep 17 00:00:00 2001 From: Nurit Izrailov <38442135+nuritizra@users.noreply.github.com> Date: Mon, 6 May 2019 11:25:31 -0400 Subject: [PATCH] adding filter usage in the example --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index fd56b71..984141c 100644 --- a/README.md +++ b/README.md @@ -265,6 +265,22 @@ data=events) In the email template `risky_toaster_template.html` we can do more grouping or sorting, assuming that one toaster owner is responsible for several toasters. For example alerts can be sorted by location or grouped by new/old status, first presenting all newly discovered risky toasters, and then having a reminder list about the still open issues for toasters that have been reported before but are not fixed yet. +### Filter + +You can use our filter decorator as well, in cases you would want to filter messages by defined conditions before saving them into the DB. + +In our example we assume that we have a filter function which includes filtering events only if their owner is one of our alpha customers, which we define in a different config file. + +```python +@APP.register_filter('riskytoaster') +def filter(event): + event_owner = event['owner'] + if event_owner in config.ALPHA_CUSTOMERS: + return event + return None +``` + +If the owner is not one of our alpha customers, we return None so that later the event won't be saved into the database. # Code of Conduct