Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

#43: Make the Hook model available for extension #44

Merged
merged 3 commits into from
Apr 22, 2017
Merged

#43: Make the Hook model available for extension #44

merged 3 commits into from
Apr 22, 2017

Conversation

tdruez
Copy link
Contributor

@tdruez tdruez commented Apr 21, 2017

  • Renamed Hook model to AbstractHook with the Meta abstract = True
  • The Hook model is the concrete implementation of the AbstractHook model
  • Those changes are no disruptive and do not require migrations

This change allows to customize the Hook model locally, for example:

from django.db import models

from rest_hooks.models import AbstractHook

class CustomHook(AbstractHook):
    is_active = models.BooleanField(default=True)

This PR is incomplete at the moment but it's a base for discussion.
Now that I can have my custom Hook model, I'm wondering about the best way it can be used in find_and_fire_hook https://github.com/zapier/django-rest-hooks/blob/master/rest_hooks/utils.py#L62 in place of the Hardcoded one.
One approach could be a settings, default to rest_hooks.models.Hook

Also, I'd like to be able to easily customized find_and_fire_hook() in general to craft the any filters relevant to my custom model.
Using my previous example, I'd like to be able to do something like

filters['is_active'] = True
hooks = CustomHook.objects.filter(**filters)

Since I want control over the model and the filters, all we may need is a simple and clean way to extend/replace find_and_fire_hook().
Maybe a setting in the fashion of the current HOOK_DELIVERER one, using find_and_fire_hook() by default, but could be override by a function/class that is responsible to return the list of hooks to be triggered.

@avelis I'd like your thoughts on this :)

 * Renamed Hook model to AbstractHook with the Meta abstract = True
 * The Hook model is the concrete implementation of the AbstractHook model
Copy link
Member

@bryanhelmig bryanhelmig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig it! We'll get it merged up and released soon.

@avelis
Copy link
Contributor

avelis commented Apr 21, 2017

@tdruez First off, thanks for the PR! If you can add some docs to the readme about creating a custom concrete class (as you code sampled above) that would go great with this PR as a merge alone.

I believe both the Hook model imports and the method call be converted to be settings oriented with defaults setup as they work now. e.g.:

  • HOOK_MODEL: To define the concrete Hook class.
  • HOOK_FINDER: Method to find and fire the hook models.

I am not completely sold on the FINDER suffix. If you can think of a more appropriate suffix I am all for it.

Lastly, have fun. It's contributions like this that make this repo and the OSS community great.

@tdruez
Copy link
Contributor Author

tdruez commented Apr 21, 2017

@bryanhelmig great! Although let me add the following suggestions before a merge, since the current commit is not yet super valuable by itself.

@avelis My pleasure, rest-hooks is already is very nice lib as-is, I just need a little before flexibility for which I'm happy to contribute.

Plan:

@avelis avelis merged commit 5a07110 into zapier:master Apr 22, 2017
@avelis
Copy link
Contributor

avelis commented Apr 22, 2017

@tdruez Thanks again for the contribution!

@tdruez
Copy link
Contributor Author

tdruez commented May 1, 2017

@avelis Thanks for the merge!
I've been running the master branch including the new extendable model successfully for a week now.
Would you mind to issue a new release and publish it on pypi?

@tdruez tdruez deleted the 43-extendable-hook-model branch May 1, 2017 15:31
@avelis
Copy link
Contributor

avelis commented May 1, 2017

@tdruez I will definitely be working on that soon.

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

Successfully merging this pull request may close these issues.

3 participants