404
+ +Page not found
+ + +diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/404.html b/404.html new file mode 100644 index 0000000..1c23420 --- /dev/null +++ b/404.html @@ -0,0 +1,113 @@ + + +
+ + + + +Page not found
+ + +pip install django-signal-webhooks
+Documentation: https://mrthearman.github.io/django-signal-webhooks/
+Source Code: https://github.com/MrThearMan/django-signal-webhooks/
+Contributing: https://github.com/MrThearMan/django-signal-webhooks/blob/main/CONTRIBUTING.md
+This library enables you to add webhooks to a Django project for any create/update/delete +events on your models with a simple configuration. New webhooks can be added in the +admin panel, with or without authentication, with plenty of hooks into the webhook sending +process to customize them for your needs.
+# project/settings.py
+
+# Add to instaled apps
+INSTALLED_APPS = [
+ ...
+ "signal_webhooks",
+ ...
+]
+
+# Add default webhook configuration to the User model
+SIGNAL_WEBHOOKS = {
+ "HOOKS": {
+ "django.contrib.auth.models.User": ...,
+ },
+}
+
+ ' + escapeHtml(summary) +'
' + noResultsText + '
'); + } +} + +function doSearch () { + var query = document.getElementById('mkdocs-search-query').value; + if (query.length > min_search_length) { + if (!window.Worker) { + displayResults(search(query)); + } else { + searchWorker.postMessage({query: query}); + } + } else { + // Clear results for short queries + displayResults([]); + } +} + +function initSearch () { + var search_input = document.getElementById('mkdocs-search-query'); + if (search_input) { + search_input.addEventListener("keyup", doSearch); + } + var term = getSearchTermFromLocation(); + if (term) { + search_input.value = term; + doSearch(); + } +} + +function onWorkerMessage (e) { + if (e.data.allowSearch) { + initSearch(); + } else if (e.data.results) { + var results = e.data.results; + displayResults(results); + } else if (e.data.config) { + min_search_length = e.data.config.min_search_length-1; + } +} + +if (!window.Worker) { + console.log('Web Worker API not supported'); + // load index in main thread + $.getScript(joinUrl(base_url, "search/worker.js")).done(function () { + console.log('Loaded worker'); + init(); + window.postMessage = function (msg) { + onWorkerMessage({data: msg}); + }; + }).fail(function (jqxhr, settings, exception) { + console.error('Could not load worker.js'); + }); +} else { + // Wrap search in a web worker + var searchWorker = new Worker(joinUrl(base_url, "search/worker.js")); + searchWorker.postMessage({init: true}); + searchWorker.onmessage = onWorkerMessage; +} diff --git a/search/search_index.json b/search/search_index.json new file mode 100644 index 0000000..23af51e --- /dev/null +++ b/search/search_index.json @@ -0,0 +1 @@ +{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"Django Signal Webhooks pip install django-signal-webhooks Documentation : https://mrthearman.github.io/django-signal-webhooks/ Source Code : https://github.com/MrThearMan/django-signal-webhooks/ Contributing : https://github.com/MrThearMan/django-signal-webhooks/blob/main/CONTRIBUTING.md This library enables you to add webhooks to a Django project for any create/update/delete events on your models with a simple configuration. New webhooks can be added in the admin panel, with or without authentication, with plenty of hooks into the webhook sending process to customize them for your needs. # project/settings.py # Add to instaled apps INSTALLED_APPS = [ ... \"signal_webhooks\", ... ] # Add default webhook configuration to the User model SIGNAL_WEBHOOKS = { \"HOOKS\": { \"django.contrib.auth.models.User\": ..., }, }","title":"Home"},{"location":"#django-signal-webhooks","text":"pip install django-signal-webhooks Documentation : https://mrthearman.github.io/django-signal-webhooks/ Source Code : https://github.com/MrThearMan/django-signal-webhooks/ Contributing : https://github.com/MrThearMan/django-signal-webhooks/blob/main/CONTRIBUTING.md This library enables you to add webhooks to a Django project for any create/update/delete events on your models with a simple configuration. New webhooks can be added in the admin panel, with or without authentication, with plenty of hooks into the webhook sending process to customize them for your needs. # project/settings.py # Add to instaled apps INSTALLED_APPS = [ ... \"signal_webhooks\", ... ] # Add default webhook configuration to the User model SIGNAL_WEBHOOKS = { \"HOOKS\": { \"django.contrib.auth.models.User\": ..., }, }","title":"Django Signal Webhooks"},{"location":"setup/","text":"Setup \u2460 Add app to INSTALLED_APPS # project/settings.py INSTALLED_APPS = [ ... \"signal_webhooks\", ... ] \u2461 Run migrations python manage.py migrate You should now see the webhooks section in django's admin panel. \u2462 Define webhook settings The easiest way to add webhooks is just to use the default configuration by settings ... (ellipses) to a model in the HOOKS confiuration option. # project/settings.py SIGNAL_WEBHOOKS = { \"HOOKS\": { # Add default webhook configuration to the User model \"django.contrib.auth.models.User\": ..., }, } This will allow webhooks to be fired for the User model. You can also set the value to a string in dot import notation, pointing to a custom function, or to None to explicitly forbid hooks for a given model. You can also set these for each signal separately. # project/settings.py SIGNAL_WEBHOOKS = { \"HOOKS\": { \"django.contrib.auth.models.User\": { \"CREATE\": None, \"UPDATE\": \"my.custom.func\", \"DELETE\": ..., }, }, } \u2463 Add hooks in the admin panel You must give each webhook a unique name, the signals it listens to, the references model (in dot import notation), and the endpoint it will call. You can also set any headers you want, as well as an authentication token that will be used in the Authorization header in the webhook. This token will be ciphered using SIGNAL_WEBHOOKS.CIPHER_KEY when saved to the database to prevent it from being stolen. Ticking the keep_last_reponse checkbox will allow webhook responses to be recorded in the last_reponse field. \u2464 That's it! Webhooks should now be fired for the defined signals. Here is an example of what the default configuration will send for the User model. { \"model\": \"auth.user\", \"pk\": 1, \"fields\": { \"password\": \"pbkdf2_sha256$390000$79U11eoHYvz4v33cXo5373$bNN8Q0NpvOowd1od9pBUNG1WJ4zUIz4eOlaSOQNbop8=\", \"last_login\": null, \"is_superuser\": false, \"username\": \"foo\", \"first_name\": \"\", \"last_name\": \"\", \"email\": \"\", \"is_staff\": false, \"is_active\": true, \"date_joined\": \"2022-08-21 20:37:38.714905+00:00\", \"groups\": [], \"user_permissions\": [] } } You can set different data for these requests in various ways, like with SIGNAL_WEBHOOKS.SERIALIZER setting, or on per-model basis by defining a webhook_data method on the model. Have a look at the available settings .","title":"Setup"},{"location":"setup/#setup","text":"","title":"Setup"},{"location":"setup/#1-add-app-to-installed_apps","text":"# project/settings.py INSTALLED_APPS = [ ... \"signal_webhooks\", ... ]","title":"\u2460 Add app to INSTALLED_APPS"},{"location":"setup/#2-run-migrations","text":"python manage.py migrate You should now see the webhooks section in django's admin panel.","title":"\u2461 Run migrations"},{"location":"setup/#3-define-webhook-settings","text":"The easiest way to add webhooks is just to use the default configuration by settings ... (ellipses) to a model in the HOOKS confiuration option. # project/settings.py SIGNAL_WEBHOOKS = { \"HOOKS\": { # Add default webhook configuration to the User model \"django.contrib.auth.models.User\": ..., }, } This will allow webhooks to be fired for the User model. You can also set the value to a string in dot import notation, pointing to a custom function, or to None to explicitly forbid hooks for a given model. You can also set these for each signal separately. # project/settings.py SIGNAL_WEBHOOKS = { \"HOOKS\": { \"django.contrib.auth.models.User\": { \"CREATE\": None, \"UPDATE\": \"my.custom.func\", \"DELETE\": ..., }, }, }","title":"\u2462 Define webhook settings"},{"location":"setup/#4-add-hooks-in-the-admin-panel","text":"You must give each webhook a unique name, the signals it listens to, the references model (in dot import notation), and the endpoint it will call. You can also set any headers you want, as well as an authentication token that will be used in the Authorization header in the webhook. This token will be ciphered using SIGNAL_WEBHOOKS.CIPHER_KEY when saved to the database to prevent it from being stolen. Ticking the keep_last_reponse checkbox will allow webhook responses to be recorded in the last_reponse field.","title":"\u2463 Add hooks in the admin panel"},{"location":"setup/#5-thats-it","text":"Webhooks should now be fired for the defined signals. Here is an example of what the default configuration will send for the User model. { \"model\": \"auth.user\", \"pk\": 1, \"fields\": { \"password\": \"pbkdf2_sha256$390000$79U11eoHYvz4v33cXo5373$bNN8Q0NpvOowd1od9pBUNG1WJ4zUIz4eOlaSOQNbop8=\", \"last_login\": null, \"is_superuser\": false, \"username\": \"foo\", \"first_name\": \"\", \"last_name\": \"\", \"email\": \"\", \"is_staff\": false, \"is_active\": true, \"date_joined\": \"2022-08-21 20:37:38.714905+00:00\", \"groups\": [], \"user_permissions\": [] } } You can set different data for these requests in various ways, like with SIGNAL_WEBHOOKS.SERIALIZER setting, or on per-model basis by defining a webhook_data method on the model. Have a look at the available settings .","title":"\u2464 That's it!"}]} \ No newline at end of file diff --git a/search/worker.js b/search/worker.js new file mode 100644 index 0000000..8628dbc --- /dev/null +++ b/search/worker.js @@ -0,0 +1,133 @@ +var base_path = 'function' === typeof importScripts ? '.' : '/search/'; +var allowSearch = false; +var index; +var documents = {}; +var lang = ['en']; +var data; + +function getScript(script, callback) { + console.log('Loading script: ' + script); + $.getScript(base_path + script).done(function () { + callback(); + }).fail(function (jqxhr, settings, exception) { + console.log('Error: ' + exception); + }); +} + +function getScriptsInOrder(scripts, callback) { + if (scripts.length === 0) { + callback(); + return; + } + getScript(scripts[0], function() { + getScriptsInOrder(scripts.slice(1), callback); + }); +} + +function loadScripts(urls, callback) { + if( 'function' === typeof importScripts ) { + importScripts.apply(null, urls); + callback(); + } else { + getScriptsInOrder(urls, callback); + } +} + +function onJSONLoaded () { + data = JSON.parse(this.responseText); + var scriptsToLoad = ['lunr.js']; + if (data.config && data.config.lang && data.config.lang.length) { + lang = data.config.lang; + } + if (lang.length > 1 || lang[0] !== "en") { + scriptsToLoad.push('lunr.stemmer.support.js'); + if (lang.length > 1) { + scriptsToLoad.push('lunr.multi.js'); + } + if (lang.includes("ja") || lang.includes("jp")) { + scriptsToLoad.push('tinyseg.js'); + } + for (var i=0; i < lang.length; i++) { + if (lang[i] != 'en') { + scriptsToLoad.push(['lunr', lang[i], 'js'].join('.')); + } + } + } + loadScripts(scriptsToLoad, onScriptsLoaded); +} + +function onScriptsLoaded () { + console.log('All search scripts loaded, building Lunr index...'); + if (data.config && data.config.separator && data.config.separator.length) { + lunr.tokenizer.separator = new RegExp(data.config.separator); + } + + if (data.index) { + index = lunr.Index.load(data.index); + data.docs.forEach(function (doc) { + documents[doc.location] = doc; + }); + console.log('Lunr pre-built index loaded, search ready'); + } else { + index = lunr(function () { + if (lang.length === 1 && lang[0] !== "en" && lunr[lang[0]]) { + this.use(lunr[lang[0]]); + } else if (lang.length > 1) { + this.use(lunr.multiLanguage.apply(null, lang)); // spread operator not supported in all browsers: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator#Browser_compatibility + } + this.field('title'); + this.field('text'); + this.ref('location'); + + for (var i=0; i < data.docs.length; i++) { + var doc = data.docs[i]; + this.add(doc); + documents[doc.location] = doc; + } + }); + console.log('Lunr index built, search ready'); + } + allowSearch = true; + postMessage({config: data.config}); + postMessage({allowSearch: allowSearch}); +} + +function init () { + var oReq = new XMLHttpRequest(); + oReq.addEventListener("load", onJSONLoaded); + var index_path = base_path + '/search_index.json'; + if( 'function' === typeof importScripts ){ + index_path = 'search_index.json'; + } + oReq.open("GET", index_path); + oReq.send(); +} + +function search (query) { + if (!allowSearch) { + console.error('Assets for search still loading'); + return; + } + + var resultDocuments = []; + var results = index.search(query); + for (var i=0; i < results.length; i++){ + var result = results[i]; + doc = documents[result.ref]; + doc.summary = doc.text.substring(0, 200); + resultDocuments.push(doc); + } + return resultDocuments; +} + +if( 'function' === typeof importScripts ) { + onmessage = function (e) { + if (e.data.init) { + init(); + } else if (e.data.query) { + postMessage({ results: search(e.data.query) }); + } else { + console.error("Worker - Unrecognized message: " + e); + } + }; +} diff --git a/setup/index.html b/setup/index.html new file mode 100644 index 0000000..4fc3730 --- /dev/null +++ b/setup/index.html @@ -0,0 +1,210 @@ + + + + + + + +INSTALLED_APPS
# project/settings.py
+
+INSTALLED_APPS = [
+ ...
+ "signal_webhooks",
+ ...
+]
+python manage.py migrate
+You should now see the webhooks section in django's admin panel.
+The easiest way to add webhooks is just to use the default +configuration by settings ... (ellipses) to a model in the +HOOKS confiuration option.
+# project/settings.py
+
+SIGNAL_WEBHOOKS = {
+ "HOOKS": {
+ # Add default webhook configuration to the User model
+ "django.contrib.auth.models.User": ...,
+ },
+}
+This will allow webhooks to be fired for the User model. +You can also set the value to a string in dot import notation, +pointing to a custom function, or to None to explicitly forbid +hooks for a given model. You can also set these for each signal +separately.
+# project/settings.py
+
+SIGNAL_WEBHOOKS = {
+ "HOOKS": {
+ "django.contrib.auth.models.User": {
+ "CREATE": None,
+ "UPDATE": "my.custom.func",
+ "DELETE": ...,
+ },
+ },
+}
+You must give each webhook a unique name, the signals it listens to,
+the references model (in dot import notation), and the endpoint
+it will call. You can also set any headers you want, as well as
+an authentication token that will be used in the Authorization
+header in the webhook. This token will be ciphered using
+SIGNAL_WEBHOOKS.CIPHER_KEY
when saved to the database to
+prevent it from being stolen. Ticking the keep_last_reponse
+checkbox will allow webhook responses to be recorded in the
+last_reponse
field.
Webhooks should now be fired for the defined signals. Here is an +example of what the default configuration will send for the User +model.
+{
+ "model": "auth.user",
+ "pk": 1,
+ "fields": {
+ "password": "pbkdf2_sha256$390000$79U11eoHYvz4v33cXo5373$bNN8Q0NpvOowd1od9pBUNG1WJ4zUIz4eOlaSOQNbop8=",
+ "last_login": null,
+ "is_superuser": false,
+ "username": "foo",
+ "first_name": "",
+ "last_name": "",
+ "email": "",
+ "is_staff": false,
+ "is_active": true,
+ "date_joined": "2022-08-21 20:37:38.714905+00:00",
+ "groups": [],
+ "user_permissions": []
+ }
+}
+You can set different data for these requests in various ways,
+like with SIGNAL_WEBHOOKS.SERIALIZER
setting, or on per-model
+basis by defining a webhook_data
method on the model.
+Have a look at the available settings.