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

Commit d21a070

Browse files
imposerenavelis
authored andcommitted
Receiver of raw_hook_event now uses the same logic as receivers of other
Should fix #58 Some backward incompatible changes were introduced (see README.md)
1 parent 2a2d6a4 commit d21a070

14 files changed

+326
-115
lines changed

.travis.yml

-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ python:
77
- "3.6"
88

99
env:
10-
- DJANGO_VERSION="1.4"
1110
- DJANGO_VERSION="1.5"
1211
- DJANGO_VERSION="1.6"
1312
- DJANGO_VERSION="1.7"
@@ -24,10 +23,6 @@ script: python runtests.py
2423

2524
matrix:
2625
exclude:
27-
- python: "3.3"
28-
env: DJANGO_VERSION="1.4"
29-
- python: "3.4"
30-
env: DJANGO_VERSION="1.4"
3126
- python: "3.3"
3227
env: DJANGO_VERSION="1.9"
3328
- python: "3.3"
@@ -36,8 +31,6 @@ matrix:
3631
env: DJANGO_VERSION="1.11"
3732
- python: "3.3"
3833
env: DJANGO_VERSION="2.0"
39-
- python: "3.6"
40-
env: DJANGO_VERSION="1.4"
4134
- python: "3.6"
4235
env: DJANGO_VERSION="1.5"
4336
- python: "3.6"

AUTHORS.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ various contributors:
99

1010
## Patches and Suggestions
1111

12-
- You?
12+
- [Bryan Helmig](https://github.com/bryanhelmig)
13+
- [Arnaud Limbourg](https://github.com/arnaudlimbourg)
14+
- [tdruez](https://github.com/tdruez)
15+
- [Maina Nick](https://github.com/mainanick)
16+
- Jonathan Moss
17+
- [Erik Wickstrom](https://github.com/erikcw)
18+
- [Yaroslav Klyuyev](https://github.com/imposeren)

README.md

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[![Travis CI Build](https://img.shields.io/travis/zapier/django-rest-hooks/master.svg)](https://travis-ci.org/zapier/django-rest-hooks)
22
[![PyPI Download](https://img.shields.io/pypi/v/django-rest-hooks.svg)](https://pypi.python.org/pypi/django-rest-hooks)
33
[![PyPI Status](https://img.shields.io/pypi/status/django-rest-hooks.svg)](https://pypi.python.org/pypi/django-rest-hooks)
4+
45
## What are Django REST Hooks?
56

67

@@ -32,6 +33,53 @@ If you want to make a Django form or API resource, you'll need to do that yourse
3233
(though we've provided some example bits of code below).
3334

3435

36+
### Changelog
37+
38+
#### Version 1.6.0:
39+
40+
Improvements:
41+
42+
* Default handler of `raw_hook_event` uses the same logic as other handlers
43+
(see "Backwards incompatible changes" for details).
44+
45+
* Lookup of event_name by model+action_name now has a complexity of `O(1)`
46+
instead of `O(len(settings.HOOK_EVENTS))`
47+
48+
* `HOOK_CUSTOM_MODEL` is now similar to `AUTH_USER_MODEL`: must be of the form
49+
`app_label.model_name` (for django 1.7+). If old value is of the form
50+
`app_label.models.model_name` then it's automatically adapted.
51+
52+
* `rest_hooks.models.Hook` is now really "swappable", so table creation is
53+
skipped if you have different `settings.HOOK_CUSTOM_MODEL`
54+
55+
* `rest_hooks.models.AbstractHook.deliver_hook` now accepts a callable as
56+
`payload_override` argument (must accept 2 arguments: hook, instance). This
57+
was added to support old behavior of `raw_custom_event`.
58+
59+
Fixes:
60+
61+
* HookAdmin.form now honors `settings.HOOK_CUSTOM_MODEL`
62+
63+
* event_name determined from action+model is now consistent between runs (see
64+
"Backwards incompatible changes")
65+
66+
Backwards incompatible changes:
67+
68+
* Dropped support for django 1.4
69+
* Custom `HOOK_FINDER`-s should accept and handle new argument `payload_override`.
70+
Built-in finder `rest_hooks.utls.find_and_fire_hook` already does this.
71+
* If several event names in `settings.HOOK_EVENTS` share the same
72+
`'app_label.model.action'` (including `'app_label.model.action+'`) then
73+
`django.core.exceptions.ImproperlyConfigured` is raised
74+
* Receiver of `raw_hook_event` now uses the same logic as receivers of other
75+
signals: checks event_name against settings.HOOK_EVENTS, verifies model (if
76+
instance is passed), uses `HOOK_FINDER`. Old behaviour can be achieved by
77+
using `trust_event_name=True`, or `instance=None` to fire a signal.
78+
* If you have `settings.HOOK_CUSTOM_MODEL` of the form different than
79+
`app_label.models.model_name` or `app_label.model_name`, then it must
80+
be changed to `app_label.model_name`.
81+
82+
3583
### Development
3684

3785
Running the tests for Django REST Hooks is very easy, just:
@@ -57,7 +105,7 @@ python runtests.py
57105
### Requirements
58106

59107
* Python 2 or 3 (tested on 2.7, 3.3, 3.4, 3.6)
60-
* Django 1.4+ (tested on 1.5, 1.6, 1.7, 1.8, 1.9, 1.10, 1.11, 2.0)
108+
* Django 1.5+ (tested on 1.5, 1.6, 1.7, 1.8, 1.9, 1.10, 1.11, 2.0)
61109

62110
### Installing & Configuring
63111

devrequirements_1.4.txt

-2
This file was deleted.

devrequirements_1.8.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-r devrequirements.txt
2-
django-contrib-comments>=1.6.1
2+
django-contrib-comments>=1.6.1,<1.7.0
33
Django>=1.8,<1.9

devrequirements_1.9.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-r devrequirements.txt
2-
django-contrib-comments>=1.6.2
2+
django-contrib-comments>=1.6.2,<1.7.0
33
Django>=1.9,<1.10

rest_hooks/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = (1, 5, 0)
1+
VERSION = (1, 6, 0)

rest_hooks/admin.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
from django.contrib import admin
22
from django.conf import settings
33
from django import forms
4-
from rest_hooks.models import Hook
4+
from rest_hooks.utils import get_hook_model
55

6-
7-
HOOK_EVENTS = getattr(settings, 'HOOK_EVENTS', None)
8-
if HOOK_EVENTS is None:
6+
if getattr(settings, 'HOOK_EVENTS', None) is None:
97
raise Exception("You need to define settings.HOOK_EVENTS!")
108

119

10+
HookModel = get_hook_model()
11+
12+
1213
class HookForm(forms.ModelForm):
1314
"""
1415
Model form to handle registered events, asuring
1516
only events declared on HOOK_EVENTS settings
1617
can be registered.
1718
"""
18-
ADMIN_EVENTS = [(x, x) for x in HOOK_EVENTS.keys()]
1919

2020
class Meta:
21-
model = Hook
21+
model = HookModel
2222
fields = ['user', 'target', 'event']
2323

2424
def __init__(self, *args, **kwargs):
2525
super(HookForm, self).__init__(*args, **kwargs)
26-
self.fields['event'] = forms.ChoiceField(choices=self.ADMIN_EVENTS)
26+
self.fields['event'] = forms.ChoiceField(choices=self.get_admin_events())
27+
28+
@classmethod
29+
def get_admin_events(cls):
30+
return [(x, x) for x in getattr(settings, 'HOOK_EVENTS', None).keys()]
2731

2832

2933
class HookAdmin(admin.ModelAdmin):
30-
list_display = [f.name for f in Hook._meta.fields]
34+
list_display = [f.name for f in HookModel._meta.fields]
3135
raw_id_fields = ['user', ]
3236
form = HookForm
3337

34-
admin.site.register(Hook, HookAdmin)
38+
39+
admin.site.register(HookModel, HookAdmin)

rest_hooks/migrations/0001_initial.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Migration(migrations.Migration):
2424
('user', models.ForeignKey(related_name='hooks', to=settings.AUTH_USER_MODEL, on_delete=django.db.models.deletion.CASCADE)),
2525
],
2626
options={
27+
'swappable': 'HOOK_CUSTOM_MODEL',
2728
},
2829
bases=(models.Model,),
2930
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
from django.db import migrations, models
3+
4+
5+
class Migration(migrations.Migration):
6+
7+
dependencies = [
8+
('rest_hooks', '0001_initial'),
9+
]
10+
11+
operations = [
12+
migrations.AlterModelOptions(
13+
name='Hook',
14+
options={
15+
'swappable': 'HOOK_CUSTOM_MODEL',
16+
},
17+
),
18+
]

0 commit comments

Comments
 (0)