Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add per-event-type support to add_subscriber_predicate #2537

Open
mmerickel opened this issue Apr 30, 2016 · 1 comment
Open

add per-event-type support to add_subscriber_predicate #2537

mmerickel opened this issue Apr 30, 2016 · 1 comment

Comments

@mmerickel
Copy link
Member

As described in #1545 (comment) we should add event= to the config.add_subscriber_predicate API to allow a different predicate per-event-type. This can be done with a simple adapter. We may be able to then register some default predicates for the builtin events.

Note the biggest issue is that BeforeRender exposes the request as event['request'] instead of event.request which is a big reason an adapter-based api is necessary, but also because events have no required format.

@mmerickel
Copy link
Member Author

The alternative of course is to simply handle the various event types inside each individual predicate instead of registering adapters.

class ContextPredicate(object):
    def __init__(self, val, config):
        self.val = val

    def __call__(self, event):
        if isinstance(event, BeforeRender):
            request = event['request']
        else:
            request = event.request

This is what you currently have to do with no changes, and personally I find to be reasonable. I just opened this issue incase someone was offended by it and was looking for a way to improve things similar to the efforts in #1545.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant